[cfe-commits] r51362 - /cfe/trunk/lib/AST/TranslationUnit.cpp

Eli Friedman eli.friedman at gmail.com
Tue May 20 22:01:55 PDT 2008


Author: efriedma
Date: Wed May 21 00:01:55 2008
New Revision: 51362

URL: http://llvm.org/viewvc/llvm-project?rev=51362&view=rev
Log:
Don't kill the declarations if the translation unit doesn't own them 
(specifically, for TranslationUnits created from SerializationTest.cpp).  
Fixes a double-free bug in the serialization tests.


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

Modified: cfe/trunk/lib/AST/TranslationUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TranslationUnit.cpp?rev=51362&r1=51361&r2=51362&view=diff

==============================================================================
--- cfe/trunk/lib/AST/TranslationUnit.cpp (original)
+++ cfe/trunk/lib/AST/TranslationUnit.cpp Wed May 21 00:01:55 2008
@@ -31,21 +31,18 @@
        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);





More information about the cfe-commits mailing list