summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorManman Ren <manman.ren@gmail.com>2015-02-25 21:20:53 +0000
committerManman Ren <manman.ren@gmail.com>2015-02-25 21:20:53 +0000
commit082a336a8913c661aea1d4f06cb79804171c016b (patch)
treebfe295284f5bf08e2d01c625059456351674df32 /llvm/lib
parente1bbad9eb2eababecc21ace975bb25129891da38 (diff)
downloadbcm5719-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.cpp19
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();
OpenPOWER on IntegriCloud