]> granicus.if.org Git - clang/commitdiff
PR19562: Fix memory leak when ObjC interface types cause the creation of further...
authorDavid Blaikie <dblaikie@gmail.com>
Wed, 7 May 2014 06:18:00 +0000 (06:18 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Wed, 7 May 2014 06:18:00 +0000 (06:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208161 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDebugInfo.cpp

index b62cc2546fb3f0f697587e54f06d0379555e29bd..5aeeaa41436176f80e3d81077ec014bec0d6be40 100644 (file)
@@ -3332,11 +3332,15 @@ void CGDebugInfo::finalize() {
     Ty.replaceAllUsesWith(CGM.getLLVMContext(), RepTy);
   }
 
-  for (auto E : ObjCInterfaceCache)
+  // Creating types might create further types - invalidating the current
+  // element and the size(), so don't cache/reference them.
+  for (size_t i = 0; i != ObjCInterfaceCache.size(); ++i) {
+    ObjCInterfaceCacheEntry E = ObjCInterfaceCache[i];
     E.Decl.replaceAllUsesWith(CGM.getLLVMContext(),
                               E.Type->getDecl()->getDefinition()
                                   ? CreateTypeDefinition(E.Type, E.Unit)
                                   : E.Decl);
+  }
 
   // We keep our own list of retained types, because we need to look
   // up the final type in the type cache.