]> granicus.if.org Git - llvm/commitdiff
Fixing a possible memory leak from a failing realloc() call.
authorAaron Ballman <aaron@aaronballman.com>
Mon, 18 Nov 2013 17:33:32 +0000 (17:33 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Mon, 18 Nov 2013 17:33:32 +0000 (17:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195018 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/SmallPtrSet.cpp

index f0fed7792ce60ab1536e16c815a3aa9358ac3f54..dd417b453ef0e3fafbaeec01e8ec49be14f0c7f0 100644 (file)
@@ -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?");
   }