summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/PPDirectives.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-10-19 21:30:15 +0000
committerTed Kremenek <kremenek@apple.com>2010-10-19 21:30:15 +0000
commite75b876fb9b57aeb46a1acdcab12e2975efd8d10 (patch)
tree11933a93bd1d794effc0773bfc3f1c57c7012786 /clang/lib/Lex/PPDirectives.cpp
parentb865f7e025539adce4f4219cc5bc3a54f773503e (diff)
downloadbcm5719-llvm-e75b876fb9b57aeb46a1acdcab12e2975efd8d10.tar.gz
bcm5719-llvm-e75b876fb9b57aeb46a1acdcab12e2975efd8d10.zip
Really fix: <rdar://problem/8361834> MacroInfo::AddTokenToBody() leaks memory
The problem was not the management of MacroInfo objects, but that when we recycle them via the MICache the memory of the underlying SmallVector (within MacroInfo) was not getting released. This is because objects stashed into MICache simply are reused with a placement new, and never have their destructor called. llvm-svn: 116862
Diffstat (limited to 'clang/lib/Lex/PPDirectives.cpp')
-rw-r--r--clang/lib/Lex/PPDirectives.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index ffdc6ae5894..9138af064f2 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -37,7 +37,7 @@ MacroInfo *Preprocessor::AllocateMacroInfo() {
MacroInfoChain *MIChain = BP.Allocate<MacroInfoChain>();
MIChain->Next = MIChainHead;
MIChainHead = MIChain;
- MI = &(MIChainHead->MI);
+ MI = &(MIChain->MI);
}
return MI;
}
@@ -58,7 +58,11 @@ MacroInfo *Preprocessor::CloneMacroInfo(const MacroInfo &MacroToClone) {
/// be reused for allocating new MacroInfo objects.
void Preprocessor::ReleaseMacroInfo(MacroInfo *MI) {
MICache.push_back(MI);
- MI->FreeArgumentList();
+ // We need to call 'Destroy' as opposed to 'FreeArgumentList' because
+ // the MICache object will get reused with a placement new. This does
+ // not cause the underlying SmallVector to get it's memory released, so
+ // we need to call Destroy() here.
+ MI->Destroy();
}
OpenPOWER on IntegriCloud