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.

llvm-svn: 105659
This commit is contained in:
Ted Kremenek 2010-06-08 23:00:58 +00:00
parent dea66e3e4c
commit 076baeb03e
1 changed files with 10 additions and 7 deletions

View File

@ -89,13 +89,6 @@ ASTContext::~ASTContext() {
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 @@ ASTContext::~ASTContext() {
}
}
// 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(),