diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2013-11-18 17:33:32 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2013-11-18 17:33:32 +0000 |
commit | eae6e546ec5339179b4c7401416fbf2d641a9e90 (patch) | |
tree | cea60b48bf6e944ff6e9e93483e442ae0b783c71 /lib/Support/SmallPtrSet.cpp | |
parent | 6919bec07f9c4ee57a0e99f263b63546b386f22b (diff) | |
download | external_llvm-eae6e546ec5339179b4c7401416fbf2d641a9e90.zip external_llvm-eae6e546ec5339179b4c7401416fbf2d641a9e90.tar.gz external_llvm-eae6e546ec5339179b4c7401416fbf2d641a9e90.tar.bz2 |
Fixing a possible memory leak from a failing realloc() call.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195018 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/SmallPtrSet.cpp')
-rw-r--r-- | lib/Support/SmallPtrSet.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/Support/SmallPtrSet.cpp b/lib/Support/SmallPtrSet.cpp index f0fed77..dd417b4 100644 --- a/lib/Support/SmallPtrSet.cpp +++ b/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?"); } |