[cfe-commits] r116862 - /cfe/trunk/lib/Lex/PPDirectives.cpp

Ted Kremenek kremenek at apple.com
Tue Oct 19 14:30:15 PDT 2010


Author: kremenek
Date: Tue Oct 19 16:30:15 2010
New Revision: 116862

URL: http://llvm.org/viewvc/llvm-project?rev=116862&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Lex/PPDirectives.cpp

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=116862&r1=116861&r2=116862&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Oct 19 16:30:15 2010
@@ -37,7 +37,7 @@
     MacroInfoChain *MIChain = BP.Allocate<MacroInfoChain>();
     MIChain->Next = MIChainHead;
     MIChainHead = MIChain;
-    MI = &(MIChainHead->MI);
+    MI = &(MIChain->MI);
   }
   return MI;
 }
@@ -58,7 +58,11 @@
 ///  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();
 }
 
 





More information about the cfe-commits mailing list