Remember to free the heap allocated array if we're not going to use it.
authorOwen Anderson <resistor@mac.com>
Thu, 19 Jul 2007 06:45:33 +0000 (06:45 +0000)
committerOwen Anderson <resistor@mac.com>
Thu, 19 Jul 2007 06:45:33 +0000 (06:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40043 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/SmallPtrSet.cpp

index b2c5c42e2792521db62ed277b9630264c1405e43..122a71da929ace988e378dd3ee18c3cc0cac5c0d 100644 (file)
@@ -186,10 +186,12 @@ void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) {
            "Cannot assign sets with different small sizes");
            
   // If we're becoming small, prepare to insert into our stack space
-  if (RHS.isSmall())
+  if (RHS.isSmall()) {
+    if (!isSmall())
+      free(CurArray);
     CurArray = &SmallArray[0];
   // Otherwise, allocate new heap space (unless we were the same size)
-  else if (CurArraySize != RHS.CurArraySize) {
+  else if (CurArraySize != RHS.CurArraySize) {
     if (isSmall())
       CurArray = (void**)malloc(sizeof(void*) * (RHS.CurArraySize+1));
     else