summaryrefslogtreecommitdiff
path: root/lib/ExecutionEngine/MCJIT
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2014-04-29 21:52:46 +0000
committerDavid Blaikie <dblaikie@gmail.com>2014-04-29 21:52:46 +0000
commit00121bb932ddbf026297f357c2d3cdf1414f628a (patch)
tree4a34633b0177e892b2b20a8753d10ffae4025eb0 /lib/ExecutionEngine/MCJIT
parent2387e9ecb164b00f0802697bd667a59fb5295626 (diff)
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')
-rw-r--r--lib/ExecutionEngine/MCJIT/MCJIT.cpp10
-rw-r--r--lib/ExecutionEngine/MCJIT/MCJIT.h2
2 files changed, 6 insertions, 6 deletions
diff --git a/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/lib/ExecutionEngine/MCJIT/MCJIT.cpp
index 6b9dff238ad..42cb4ea6d84 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)
diff --git a/lib/ExecutionEngine/MCJIT/MCJIT.h b/lib/ExecutionEngine/MCJIT/MCJIT.h
index da1e975d4cd..100e9a23fcd 100644
--- a/lib/ExecutionEngine/MCJIT/MCJIT.h
+++ b/lib/ExecutionEngine/MCJIT/MCJIT.h
@@ -239,7 +239,7 @@ public:
/// @name ExecutionEngine interface implementation
/// @{
void addModule(Module *M) override;
- void addObjectFile(object::ObjectFile *O) override;
+ void addObjectFile(std::unique_ptr<object::ObjectFile> O) override;
void addArchive(object::Archive *O) override;
bool removeModule(Module *M) override;