From: Richard Smith Date: Tue, 28 Apr 2015 01:11:23 +0000 (+0000) Subject: Fix memory leak found by asan buildbot. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a9c5b01c40806e6efc66590b487cb131cee3fd85;p=clang Fix memory leak found by asan buildbot. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235957 91177308-0d34-0410-b5e6-96231b3b80d8 --- 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.