diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-10-19 17:40:53 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-10-19 17:40:53 +0000 |
commit | e6a7dabdefd328729bdcf15a434108b4c0bc64fb (patch) | |
tree | b0cd48959e98438689fdc9f651c06a3dc3c43257 | |
parent | b275e3d4069fcc189b33e75a0611a6abd1efd28f (diff) |
In ~Preprocessor(), also cleanup the MacroInfo objects left-over from stray "#pragma push_macro" uses. This
fixes a potential memory leak.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116826 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Lex/Preprocessor.cpp | 7 | ||||
-rw-r--r-- | test/Preprocessor/pragma-pushpop-macro.c | 8 |
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 5160acf19e..56ed765924 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -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) diff --git a/test/Preprocessor/pragma-pushpop-macro.c b/test/Preprocessor/pragma-pushpop-macro.c index 87cceaa419..71b0e0e260 100644 --- a/test/Preprocessor/pragma-pushpop-macro.c +++ b/test/Preprocessor/pragma-pushpop-macro.c @@ -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 + |