]> granicus.if.org Git - clang/commitdiff
Fix memory leak found by asan buildbot.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 28 Apr 2015 01:11:23 +0000 (01:11 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 28 Apr 2015 01:11:23 +0000 (01:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235957 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/Preprocessor.h
lib/Lex/Preprocessor.cpp

index 103fa38850486a4f07c4223dd01c637dfdc13969..db3231ef2b515eae90883670c8365aa45a58b4d8 100644 (file)
@@ -408,6 +408,11 @@ class Preprocessor : public RefCountedBase<Preprocessor> {
   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;
index 92ab2af19216bfd347b6a9566a419fa1170186ac..80715d548076df1b8bfba00d187cc2dc2b521b03 100644 (file)
@@ -142,6 +142,9 @@ Preprocessor::Preprocessor(IntrusiveRefCntPtr<PreprocessorOptions> PPOpts,
 Preprocessor::~Preprocessor() {
   assert(BacktrackPositions.empty() && "EnableBacktrack/Backtrack imbalance!");
 
+  for (auto &Macro : Macros)
+    Macro.second.destroy();
+
   IncludeMacroStack.clear();
 
   // Destroy any macro definitions.