diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-04-29 21:52:46 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-04-29 21:52:46 +0000 |
commit | 00121bb932ddbf026297f357c2d3cdf1414f628a (patch) | |
tree | 4a34633b0177e892b2b20a8753d10ffae4025eb0 /lib/ExecutionEngine/MCJIT/MCJIT.cpp | |
parent | 2387e9ecb164b00f0802697bd667a59fb5295626 (diff) | |
download | llvm-00121bb932ddbf026297f357c2d3cdf1414f628a.tar.gz llvm-00121bb932ddbf026297f357c2d3cdf1414f628a.tar.bz2 llvm-00121bb932ddbf026297f357c2d3cdf1414f628a.tar.xz |
PR19553: Memory leak in RuntimeDyldELF::createObjectImageFromFile
This starts in MCJIT::getSymbolAddress where the
unique_ptr<object::Binary> is release()d and (after a cast) passed to a
single caller, MCJIT::addObjectFile.
addObjectFile calls RuntimeDyld::loadObject.
RuntimeDld::loadObject calls RuntimeDyldELF::createObjectFromFile
And the pointer is never owned at this point. I say this point, because
the alternative codepath, RuntimeDyldMachO::createObjectFile certainly
does take ownership, so this seemed like a good hint that this was a/the
right place to take ownership.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207580 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/MCJIT/MCJIT.cpp')
-rw-r--r-- | lib/ExecutionEngine/MCJIT/MCJIT.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/lib/ExecutionEngine/MCJIT/MCJIT.cpp index 6b9dff238a..42cb4ea6d8 100644 --- a/lib/ExecutionEngine/MCJIT/MCJIT.cpp +++ b/lib/ExecutionEngine/MCJIT/MCJIT.cpp @@ -113,8 +113,8 @@ bool MCJIT::removeModule(Module *M) { -void MCJIT::addObjectFile(object::ObjectFile *Obj) { - ObjectImage *LoadedObject = Dyld.loadObject(Obj); +void MCJIT::addObjectFile(std::unique_ptr<object::ObjectFile> Obj) { + ObjectImage *LoadedObject = Dyld.loadObject(std::move(Obj)); if (!LoadedObject || Dyld.hasError()) report_fatal_error(Dyld.getErrorString()); @@ -308,10 +308,10 @@ uint64_t MCJIT::getSymbolAddress(const std::string &Name, std::unique_ptr<object::Binary> ChildBin; // FIXME: Support nested archives? if (!ChildIt->getAsBinary(ChildBin) && ChildBin->isObject()) { - object::ObjectFile *OF = reinterpret_cast<object::ObjectFile *>( - ChildBin.release()); + std::unique_ptr<object::ObjectFile> OF( + static_cast<object::ObjectFile *>(ChildBin.release())); // This causes the object file to be loaded. - addObjectFile(OF); + addObjectFile(std::move(OF)); // The address should be here now. Addr = getExistingSymbolAddress(Name); if (Addr) |