summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/SmallPtrSet.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2013-11-18 17:33:32 +0000
committerAaron Ballman <aaron@aaronballman.com>2013-11-18 17:33:32 +0000
commit5de2378f7ea44d3a3d9488d37d63cd12b0b8e8b0 (patch)
tree90c13da43e2d0858a250ed864741c6edffef61b3 /llvm/lib/Support/SmallPtrSet.cpp
parenta8553497a3497e33195374cfea397e11b385dfdd (diff)
downloadbcm5719-llvm-5de2378f7ea44d3a3d9488d37d63cd12b0b8e8b0.tar.gz
bcm5719-llvm-5de2378f7ea44d3a3d9488d37d63cd12b0b8e8b0.zip
Fixing a possible memory leak from a failing realloc() call.
llvm-svn: 195018
Diffstat (limited to 'llvm/lib/Support/SmallPtrSet.cpp')
-rw-r--r--llvm/lib/Support/SmallPtrSet.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/llvm/lib/Support/SmallPtrSet.cpp b/llvm/lib/Support/SmallPtrSet.cpp
index f0fed7792ce..dd417b453ef 100644
--- a/llvm/lib/Support/SmallPtrSet.cpp
+++ b/llvm/lib/Support/SmallPtrSet.cpp
@@ -202,8 +202,13 @@ void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) {
} 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?");
}
OpenPOWER on IntegriCloud