diff options
| author | Manman Ren <manman.ren@gmail.com> | 2015-02-25 21:20:53 +0000 |
|---|---|---|
| committer | Manman Ren <manman.ren@gmail.com> | 2015-02-25 21:20:53 +0000 |
| commit | 082a336a8913c661aea1d4f06cb79804171c016b (patch) | |
| tree | bfe295284f5bf08e2d01c625059456351674df32 /llvm/lib | |
| parent | e1bbad9eb2eababecc21ace975bb25129891da38 (diff) | |
| download | bcm5719-llvm-082a336a8913c661aea1d4f06cb79804171c016b.tar.gz bcm5719-llvm-082a336a8913c661aea1d4f06cb79804171c016b.zip | |
[LTO API] fix memory leakage introduced at r230290.
r230290 released the LLVM module but not the LTOModule.
rdar://19024554
llvm-svn: 230544
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/LTO/LTOCodeGenerator.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp index 1ba4159c9bf..61c27491657 100644 --- a/llvm/lib/LTO/LTOCodeGenerator.cpp +++ b/llvm/lib/LTO/LTOCodeGenerator.cpp @@ -82,16 +82,27 @@ void LTOCodeGenerator::initialize() { CodeModel = LTO_CODEGEN_PIC_MODEL_DEFAULT; DiagHandler = nullptr; DiagContext = nullptr; + OwnedModule = nullptr; initializeLTOPasses(); } +void LTOCodeGenerator::destroyMergedModule() { + if (OwnedModule) { + assert(IRLinker.getModule() == &OwnedModule->getModule() && + "The linker's module should be the same as the owned module"); + delete OwnedModule; + OwnedModule = nullptr; + } else if (IRLinker.getModule()) + IRLinker.deleteModule(); +} + LTOCodeGenerator::~LTOCodeGenerator() { + destroyMergedModule(); + delete TargetMach; TargetMach = nullptr; - IRLinker.deleteModule(); - for (std::vector<char *>::iterator I = CodegenOptions.begin(), E = CodegenOptions.end(); I != E; ++I) @@ -146,10 +157,10 @@ void LTOCodeGenerator::setModule(LTOModule *Mod) { "Expected module in same context"); // Delete the old merged module. - if (IRLinker.getModule()) - IRLinker.deleteModule(); + destroyMergedModule(); AsmUndefinedRefs.clear(); + OwnedModule = Mod; IRLinker.setModule(&Mod->getModule()); const std::vector<const char*> &Undefs = Mod->getAsmUndefinedRefs(); |

