]> granicus.if.org Git - clang/commitdiff
Really fix: <rdar://problem/8361834> MacroInfo::AddTokenToBody() leaks memory
authorTed Kremenek <kremenek@apple.com>
Tue, 19 Oct 2010 21:30:15 +0000 (21:30 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 19 Oct 2010 21:30:15 +0000 (21:30 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116862 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPDirectives.cpp

index ffdc6ae5894e67023193f3cdfa0556ce5a5a3325..9138af064f2680d8c75be30aa52fdfdea1eb12dd 100644 (file)
@@ -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();
 }