From dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9c Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 8 Jun 2010 23:00:58 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105659 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ASTContext.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 9aa8781592..75af89ee96 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -89,13 +89,6 @@ ASTContext::~ASTContext() { Deallocate(&*I++); } - for (llvm::DenseMap::iterator - I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) { - // Increment in loop to prevent using deallocated memory. - if (ASTRecordLayout *R = const_cast((I++)->second)) - R->Destroy(*this); - } - for (llvm::DenseMap::iterator I = ObjCLayouts.begin(), E = ObjCLayouts.end(); I != E; ) { @@ -105,6 +98,16 @@ ASTContext::~ASTContext() { } } + // ASTRecordLayout objects in ASTRecordLayouts must always be destroyed + // even when using the BumpPtrAllocator because they can contain + // DenseMaps. + for (llvm::DenseMap::iterator + I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) { + // Increment in loop to prevent using deallocated memory. + if (ASTRecordLayout *R = const_cast((I++)->second)) + R->Destroy(*this); + } + // Destroy nested-name-specifiers. for (llvm::FoldingSet::iterator NNS = NestedNameSpecifiers.begin(), -- 2.50.1