r235957 - Fix memory leak found by asan buildbot.

Richard Smith richard-llvm at metafoo.co.uk
Mon Apr 27 18:11:23 PDT 2015


Author: rsmith
Date: Mon Apr 27 20:11:23 2015
New Revision: 235957

URL: http://llvm.org/viewvc/llvm-project?rev=235957&view=rev
Log:
Fix memory leak found by asan buildbot.

Modified:
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/Lex/Preprocessor.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=235957&r1=235956&r2=235957&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Mon Apr 27 20:11:23 2015
@@ -408,6 +408,11 @@ class Preprocessor : public RefCountedBa
   public:
     MacroState() : MacroState(nullptr) {}
     MacroState(MacroDirective *MD) : State(MD) {}
+    void destroy() {
+      if (auto *Info = State.dyn_cast<ModuleMacroInfo*>())
+        Info->~ModuleMacroInfo();
+      State = (MacroDirective*)nullptr;
+    }
     MacroDirective *getLatest() const {
       if (auto *Info = State.dyn_cast<ModuleMacroInfo*>())
         return Info->MD;

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=235957&r1=235956&r2=235957&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Mon Apr 27 20:11:23 2015
@@ -142,6 +142,9 @@ Preprocessor::Preprocessor(IntrusiveRefC
 Preprocessor::~Preprocessor() {
   assert(BacktrackPositions.empty() && "EnableBacktrack/Backtrack imbalance!");
 
+  for (auto &Macro : Macros)
+    Macro.second.destroy();
+
   IncludeMacroStack.clear();
 
   // Destroy any macro definitions.





More information about the cfe-commits mailing list