From a9c5b01c40806e6efc66590b487cb131cee3fd85 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 28 Apr 2015 01:11:23 +0000 Subject: [PATCH] Fix memory leak found by asan buildbot. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235957 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Lex/Preprocessor.h | 5 +++++ lib/Lex/Preprocessor.cpp | 3 +++ 2 files changed, 8 insertions(+) diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 103fa38850..db3231ef2b 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -408,6 +408,11 @@ class Preprocessor : public RefCountedBase { public: MacroState() : MacroState(nullptr) {} MacroState(MacroDirective *MD) : State(MD) {} + void destroy() { + if (auto *Info = State.dyn_cast()) + Info->~ModuleMacroInfo(); + State = (MacroDirective*)nullptr; + } MacroDirective *getLatest() const { if (auto *Info = State.dyn_cast()) return Info->MD; diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 92ab2af192..80715d5480 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -142,6 +142,9 @@ Preprocessor::Preprocessor(IntrusiveRefCntPtr PPOpts, Preprocessor::~Preprocessor() { assert(BacktrackPositions.empty() && "EnableBacktrack/Backtrack imbalance!"); + for (auto &Macro : Macros) + Macro.second.destroy(); + IncludeMacroStack.clear(); // Destroy any macro definitions. -- 2.50.1