Fix memory leak found by asan buildbot.

llvm-svn: 235957
This commit is contained in:
Richard Smith 2015-04-28 01:11:23 +00:00
parent 374934cb8a
commit 66f5ab26e3
2 changed files with 8 additions and 0 deletions

View 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;

View 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.