[cfe-commits] r105659 - /cfe/trunk/lib/AST/ASTContext.cpp

Ted Kremenek kremenek at apple.com
Tue Jun 8 16:00:58 PDT 2010


Author: kremenek
Date: Tue Jun  8 18:00:58 2010
New Revision: 105659

URL: http://llvm.org/viewvc/llvm-project?rev=105659&view=rev
Log:
Fix memory leak in ASTContext where ASTRecordLayout objects involving C++ structures wouldn't have
their associated memory destroyed when using a BumpPtrAllocator.  These objects internally use
a DenseMap.

Modified:
    cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=105659&r1=105658&r2=105659&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Jun  8 18:00:58 2010
@@ -89,13 +89,6 @@
       Deallocate(&*I++);
     }
 
-    for (llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>::iterator
-         I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) {
-      // Increment in loop to prevent using deallocated memory.
-      if (ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second))
-        R->Destroy(*this);
-    }
-
     for (llvm::DenseMap<const ObjCContainerDecl*,
          const ASTRecordLayout*>::iterator
          I = ObjCLayouts.begin(), E = ObjCLayouts.end(); I != E; ) {
@@ -105,6 +98,16 @@
     }
   }
 
+  // ASTRecordLayout objects in ASTRecordLayouts must always be destroyed
+  // even when using the BumpPtrAllocator because they can contain
+  // DenseMaps.
+  for (llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>::iterator
+       I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) {
+    // Increment in loop to prevent using deallocated memory.
+    if (ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second))
+      R->Destroy(*this);
+  }
+
   // Destroy nested-name-specifiers.
   for (llvm::FoldingSet<NestedNameSpecifier>::iterator
          NNS = NestedNameSpecifiers.begin(),





More information about the cfe-commits mailing list