[cfe-commits] r116826 - in /cfe/trunk: lib/Lex/Preprocessor.cpp test/Preprocessor/pragma-pushpop-macro.c
Ted Kremenek
kremenek at apple.com
Tue Oct 19 10:40:53 PDT 2010
Author: kremenek
Date: Tue Oct 19 12:40:53 2010
New Revision: 116826
URL: http://llvm.org/viewvc/llvm-project?rev=116826&view=rev
Log:
In ~Preprocessor(), also cleanup the MacroInfo objects left-over from stray "#pragma push_macro" uses. This
fixes a potential memory leak.
Modified:
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/test/Preprocessor/pragma-pushpop-macro.c
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=116826&r1=116825&r2=116826&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Tue Oct 19 12:40:53 2010
@@ -123,6 +123,13 @@
// 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)
Modified: cfe/trunk/test/Preprocessor/pragma-pushpop-macro.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/pragma-pushpop-macro.c?rev=116826&r1=116825&r2=116826&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/pragma-pushpop-macro.c (original)
+++ cfe/trunk/test/Preprocessor/pragma-pushpop-macro.c Tue Oct 19 12:40:53 2010
@@ -25,9 +25,17 @@
#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
+
More information about the cfe-commits
mailing list