In ~Preprocessor(), also cleanup the MacroInfo objects left-over from stray "#pragma push_macro" uses. This

fixes a potential memory leak.

llvm-svn: 116826
This commit is contained in:
Ted Kremenek 2010-10-19 17:40:53 +00:00
parent 6339f1ce2f
commit 2c8028bcf4
2 changed files with 15 additions and 0 deletions

View File

@ -123,6 +123,13 @@ Preprocessor::~Preprocessor() {
// 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();
}
}
// Free any cached macro expanders.
for (unsigned i = 0, e = NumCachedTokenLexers; i != e; ++i)

View File

@ -25,9 +25,17 @@ int pmx3 = X;
#pragma pop_macro("Y")
int pmy1 = Y;
// Have a stray 'push' to show we don't crash when having inbalanced
// push/pop
#pragma push_macro("Y")
#define Y 4
int pmy2 = Y;
// CHECK: int pmx0 = 1
// CHECK: int pmy0 = 2
// CHECK: int pmx1 = 1
// CHECK: int pmx2 = 2
// CHECK: int pmx3 = 1
// CHECK: int pmy1 = 3
// CHECK: int pmy2 = 4