From: Eli Friedman Date: Wed, 21 May 2008 05:01:55 +0000 (+0000) Subject: Don't kill the declarations if the translation unit doesn't own them X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1108e7dec6d998b3945a93cb6f549e349cabf258;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51362 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/TranslationUnit.cpp b/lib/AST/TranslationUnit.cpp index 9d7758648d..bfe6ee27fb 100644 --- a/lib/AST/TranslationUnit.cpp +++ b/lib/AST/TranslationUnit.cpp @@ -31,21 +31,18 @@ enum { BasicMetadataBlock = 1, DeclsBlock = 3 }; TranslationUnit::~TranslationUnit() { - - llvm::DenseSet 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 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);