aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/Preprocessor.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-10-19 18:16:54 +0000
committerTed Kremenek <kremenek@apple.com>2010-10-19 18:16:54 +0000
commitaf8fa25c0d4e0540952a50bbd06dc1558954ccd9 (patch)
tree6d07abeb5be980fc9b4bd795528cbc365cf087fb /lib/Lex/Preprocessor.cpp
parent0d7d39939a96b42bc6aa05b31fc1095cbe246021 (diff)
Simplify lifetime management of MacroInfo objects in Preprocessor by having the Preprocessor maintain them in a linked
list of allocated MacroInfos. This requires only 1 extra pointer per MacroInfo object, and allows us to blow them away in one place. This fixes an elusive memory leak with MacroInfos (whose exact location I couldn't still figure out despite substantial digging). Fixes <rdar://problem/8361834>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116842 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/Preprocessor.cpp')
-rw-r--r--lib/Lex/Preprocessor.cpp29
1 files changed, 5 insertions, 24 deletions
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index 56ed765924..9a695004c9 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -56,7 +56,7 @@ Preprocessor::Preprocessor(Diagnostic &diags, const LangOptions &opts,
SourceMgr(SM), HeaderInfo(Headers), ExternalSource(0),
Identifiers(opts, IILookup), BuiltinInfo(Target), CodeComplete(0),
CodeCompletionFile(0), SkipMainFilePreamble(0, true), CurPPLexer(0),
- CurDirLookup(0), Callbacks(0), MacroArgCache(0), Record(0) {
+ CurDirLookup(0), Callbacks(0), MacroArgCache(0), Record(0), MIChainHead(0) {
ScratchBuf = new ScratchBuffer(SourceMgr);
CounterValue = 0; // __COUNTER__ starts at 0.
OwnsHeaderSearch = OwnsHeaders;
@@ -106,29 +106,10 @@ Preprocessor::~Preprocessor() {
}
// Free any macro definitions.
- for (llvm::DenseMap<IdentifierInfo*, MacroInfo*>::iterator I =
- Macros.begin(), E = Macros.end(); I != E; ++I) {
- // We don't need to free the MacroInfo objects directly. These
- // will be released when the BumpPtrAllocator 'BP' object gets
- // destroyed. We still need to run the dtor, however, to free
- // memory alocated by MacroInfo.
- I->second->Destroy();
- I->first->setHasMacroDefinition(false);
- }
- for (std::vector<MacroInfo*>::iterator I = MICache.begin(),
- E = MICache.end(); I != E; ++I) {
- // We don't need to free the MacroInfo objects directly. These
- // will be released when the BumpPtrAllocator 'BP' object gets
- // destroyed. We still need to run the dtor, however, to free
- // memory alocated by MacroInfo.
- (*I)->Destroy();
- }
- for (llvm::DenseMap<IdentifierInfo*, std::vector<MacroInfo*> >::iterator I =
- PragmaPushMacroInfo.begin(), E = PragmaPushMacroInfo.end(); I!=E; ++I){
- for (std::vector<MacroInfo*>::iterator I2 = I->second.begin(), E2 = I->second.end();
- I2 != E2; ++I2) {
- (*I2)->Destroy();
- }
+ for (MacroInfoChain *I = MIChainHead ; I ; ) {
+ MacroInfoChain *Next = I->Next;
+ I->MI.Destroy();
+ I = Next;
}
// Free any cached macro expanders.