From 2993cdac4091a2748b839882eca0e672171b1d6a Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Fri, 27 Mar 2009 20:56:17 +0000 Subject: [PATCH] Fix test failures caused by reading memory after freeing it. My fix is rather nasty, but I can't think of a better fix off the top of my head. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67867 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ASTContext.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 84976a0294..e433769a9c 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -81,8 +81,14 @@ ASTContext::~ASTContext() { for (llvm::FoldingSet::iterator NNS = NestedNameSpecifiers.begin(), NNSEnd = NestedNameSpecifiers.end(); - NNS != NNSEnd; ++NNS) - NNS->Destroy(*this); + NNS != NNSEnd; ) { + // This loop iterates, then destroys so that it doesn't cause invalid + // reads. + // FIXME: Find a less fragile way to do this! + NestedNameSpecifier* N = &*NNS; + ++NNS; + N->Destroy(*this); + } if (GlobalNestedNameSpecifier) GlobalNestedNameSpecifier->Destroy(*this); -- 2.40.0