diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-09-05 21:46:22 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-09-05 21:46:22 +0000 |
commit | 056bf77faf964265190c6c82d83a3d3958fe4b0d (patch) | |
tree | 5206ef80fbe11b5f5a2ac3a2a9e24b3c1ceed65a /clang/lib/Lex/ModuleMap.cpp | |
parent | f887406a7d07cbebb09a4dab3e2ce136e0676777 (diff) | |
download | bcm5719-llvm-056bf77faf964265190c6c82d83a3d3958fe4b0d.tar.gz bcm5719-llvm-056bf77faf964265190c6c82d83a3d3958fe4b0d.zip |
Fix memory leak after r312467. The ModuleMap is the owner of the global module object until it's reparented under a real module.
llvm-svn: 312580
Diffstat (limited to 'clang/lib/Lex/ModuleMap.cpp')
-rw-r--r-- | clang/lib/Lex/ModuleMap.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index db2f952e3c9..b01080e55a5 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -256,8 +256,7 @@ ModuleMap::ModuleMap(SourceManager &SourceMgr, DiagnosticsEngine &Diags, const LangOptions &LangOpts, const TargetInfo *Target, HeaderSearch &HeaderInfo) : SourceMgr(SourceMgr), Diags(Diags), LangOpts(LangOpts), Target(Target), - HeaderInfo(HeaderInfo), BuiltinIncludeDir(nullptr), - SourceModule(nullptr), NumCreatedModules(0) { + HeaderInfo(HeaderInfo) { MMapLangOpts.LineComment = true; } @@ -747,10 +746,12 @@ std::pair<Module *, bool> ModuleMap::findOrCreateModule(StringRef Name, } Module *ModuleMap::createGlobalModuleForInterfaceUnit(SourceLocation Loc) { - auto *Result = new Module("<global>", Loc, nullptr, /*IsFramework*/ false, - /*IsExplicit*/ true, NumCreatedModules++); - Result->Kind = Module::GlobalModuleFragment; - return Result; + assert(!PendingGlobalModule && "created multiple global modules"); + PendingGlobalModule.reset( + new Module("<global>", Loc, nullptr, /*IsFramework*/ false, + /*IsExplicit*/ true, NumCreatedModules++)); + PendingGlobalModule->Kind = Module::GlobalModuleFragment; + return PendingGlobalModule.get(); } Module *ModuleMap::createModuleForInterfaceUnit(SourceLocation Loc, @@ -766,7 +767,10 @@ Module *ModuleMap::createModuleForInterfaceUnit(SourceLocation Loc, Modules[Name] = SourceModule = Result; // Reparent the current global module fragment as a submodule of this module. + assert(GlobalModule == PendingGlobalModule.get() && + "unexpected global module"); GlobalModule->setParent(Result); + PendingGlobalModule.release(); // now owned by parent // Mark the main source file as being within the newly-created module so that // declarations and macros are properly visibility-restricted to it. |