[llvm] r195018 - Fixing a possible memory leak from a failing realloc() call.
Aaron Ballman
aaron at aaronballman.com
Mon Nov 18 09:33:33 PST 2013
Author: aaronballman
Date: Mon Nov 18 11:33:32 2013
New Revision: 195018
URL: http://llvm.org/viewvc/llvm-project?rev=195018&view=rev
Log:
Fixing a possible memory leak from a failing realloc() call.
Modified:
llvm/trunk/lib/Support/SmallPtrSet.cpp
Modified: llvm/trunk/lib/Support/SmallPtrSet.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SmallPtrSet.cpp?rev=195018&r1=195017&r2=195018&view=diff
==============================================================================
--- llvm/trunk/lib/Support/SmallPtrSet.cpp (original)
+++ llvm/trunk/lib/Support/SmallPtrSet.cpp Mon Nov 18 11:33:32 2013
@@ -202,8 +202,13 @@ void SmallPtrSetImpl::CopyFrom(const Sma
} else if (CurArraySize != RHS.CurArraySize) {
if (isSmall())
CurArray = (const void**)malloc(sizeof(void*) * RHS.CurArraySize);
- else
- CurArray = (const void**)realloc(CurArray, sizeof(void*)*RHS.CurArraySize);
+ else {
+ const void **T = (const void**)realloc(CurArray,
+ sizeof(void*) * RHS.CurArraySize);
+ if (!T)
+ free(CurArray);
+ CurArray = T;
+ }
assert(CurArray && "Failed to allocate memory?");
}
More information about the llvm-commits
mailing list