]> granicus.if.org Git - clang/commitdiff
Don't kill the declarations if the translation unit doesn't own them
authorEli Friedman <eli.friedman@gmail.com>
Wed, 21 May 2008 05:01:55 +0000 (05:01 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 21 May 2008 05:01:55 +0000 (05:01 +0000)
(specifically, for TranslationUnits created from SerializationTest.cpp).
Fixes a double-free bug in the serialization tests.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51362 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/TranslationUnit.cpp

index 9d7758648d527a7625b13de0e4337fbc0d0065e1..bfe6ee27fbe5bdb543080faecd5d1ae9713a7b2b 100644 (file)
@@ -31,21 +31,18 @@ enum { BasicMetadataBlock = 1,
        DeclsBlock = 3 };
 
 TranslationUnit::~TranslationUnit() {
-  
-  llvm::DenseSet<Decl*> Killed;
-  
-  for (iterator I=begin(), E=end(); I!=E; ++I) {
-    if (Killed.count(*I)) continue;
-
-    Killed.insert(*I);
-    (*I)->Destroy(*Context);
-  }
-  
   if (OwnsMetaData && Context) {
+    llvm::DenseSet<Decl*> Killed;
+    for (iterator I=begin(), E=end(); I!=E; ++I) {
+      if (Killed.count(*I)) continue;
+
+      Killed.insert(*I);
+      (*I)->Destroy(*Context);
+    }
+
     // The ASTContext object has the sole references to the IdentifierTable
     // Selectors, and the Target information.  Go and delete them, since
     // the TranslationUnit effectively owns them.
-    
     delete &(Context->Idents);
     delete &(Context->Selectors);
     delete &(Context->Target);