summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ASTContext.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-06-03 13:51:33 +0000
committerManuel Klimek <klimek@google.com>2013-06-03 13:51:33 +0000
commita732899cb43e887464e9a9134c5166e06672eacc (patch)
treecb4d2c919fa3a0549463ab8212ea34376920fe3f /clang/lib/AST/ASTContext.cpp
parentd0cf5b2de355cb5ec6ec90a7057f60a4d2a10169 (diff)
downloadbcm5719-llvm-a732899cb43e887464e9a9134c5166e06672eacc.tar.gz
bcm5719-llvm-a732899cb43e887464e9a9134c5166e06672eacc.zip
Fix memory leak for APValues that do memory allocation.
This patch ensures that APValues are deallocated with the ASTContext by registering a deallocation function for APValues to the ASTContext. Original version of the patch by James Dennett. llvm-svn: 183101
Diffstat (limited to 'clang/lib/AST/ASTContext.cpp')
-rw-r--r--clang/lib/AST/ASTContext.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index c1f31529b3d..333e80be306 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -732,10 +732,12 @@ ASTContext::~ASTContext() {
// FIXME: Is this the ideal solution?
ReleaseDeclContextMaps();
- // Call all of the deallocation functions.
- for (unsigned I = 0, N = Deallocations.size(); I != N; ++I)
- Deallocations[I].first(Deallocations[I].second);
-
+ // Call all of the deallocation functions on all of their targets.
+ for (DeallocationMap::const_iterator I = Deallocations.begin(),
+ E = Deallocations.end(); I != E; ++I)
+ for (unsigned J = 0, N = I->second.size(); J != N; ++J)
+ (I->first)((I->second)[J]);
+
// ASTRecordLayout objects in ASTRecordLayouts must always be destroyed
// because they can contain DenseMaps.
for (llvm::DenseMap<const ObjCContainerDecl*,
@@ -759,7 +761,7 @@ ASTContext::~ASTContext() {
}
void ASTContext::AddDeallocation(void (*Callback)(void*), void *Data) {
- Deallocations.push_back(std::make_pair(Callback, Data));
+ Deallocations[Callback].push_back(Data);
}
void
OpenPOWER on IntegriCloud