[llvm-branch-commits] [llvm-branch] r118532 - /llvm/branches/Apple/whitney/lib/Support/StringRef.cpp
Daniel Dunbar
daniel at zuster.org
Tue Nov 9 09:28:29 PST 2010
Author: ddunbar
Date: Tue Nov 9 11:28:29 2010
New Revision: 118532
URL: http://llvm.org/viewvc/llvm-project?rev=118532&view=rev
Log:
Merge r118370:
--
Author: Ted Kremenek <kremenek at apple.com>
Date: Sun Nov 7 06:09:02 2010 +0000
Fix memory leak in StringRef::edit_distance(). 'Allocated' could be leaked on an early return.
Modified:
llvm/branches/Apple/whitney/lib/Support/StringRef.cpp
Modified: llvm/branches/Apple/whitney/lib/Support/StringRef.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/lib/Support/StringRef.cpp?rev=118532&r1=118531&r2=118532&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/lib/Support/StringRef.cpp (original)
+++ llvm/branches/Apple/whitney/lib/Support/StringRef.cpp Tue Nov 9 11:28:29 2010
@@ -9,6 +9,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/APInt.h"
+#include "llvm/ADT/OwningPtr.h"
#include <bitset>
using namespace llvm;
@@ -84,10 +85,12 @@
const unsigned SmallBufferSize = 64;
unsigned SmallBuffer[SmallBufferSize];
- unsigned *Allocated = 0;
+ llvm::OwningArrayPtr<unsigned> Allocated;
unsigned *previous = SmallBuffer;
- if (2*(n + 1) > SmallBufferSize)
- Allocated = previous = new unsigned [2*(n+1)];
+ if (2*(n + 1) > SmallBufferSize) {
+ previous = new unsigned [2*(n+1)];
+ Allocated.reset(previous);
+ }
unsigned *current = previous + (n + 1);
for (unsigned i = 0; i <= n; ++i)
@@ -118,8 +121,6 @@
}
unsigned Result = previous[n];
- delete [] Allocated;
-
return Result;
}
More information about the llvm-branch-commits
mailing list