summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/Archive.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-06-23 21:53:12 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-06-23 21:53:12 +0000
commitc3f9b5a53458bb66899d6e90e9e032dfdfa5ba2b (patch)
treeda0146a72b490ea2f0dfd25e6f1415e70b094058 /llvm/lib/Object/Archive.cpp
parentd81c48392888bcc62ed8628ee3005a34d151ea96 (diff)
downloadbcm5719-llvm-c3f9b5a53458bb66899d6e90e9e032dfdfa5ba2b.tar.gz
bcm5719-llvm-c3f9b5a53458bb66899d6e90e9e032dfdfa5ba2b.zip
Make ObjectFile and BitcodeReader always own the MemoryBuffer.
This allows us to just use a std::unique_ptr to store the pointer to the buffer. The flip side is that they have to support releasing the buffer back to the caller. Overall this looks like a more efficient and less brittle api. llvm-svn: 211542
Diffstat (limited to 'llvm/lib/Object/Archive.cpp')
-rw-r--r--llvm/lib/Object/Archive.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/Object/Archive.cpp b/llvm/lib/Object/Archive.cpp
index 05e891384f1..cd8924920a8 100644
--- a/llvm/lib/Object/Archive.cpp
+++ b/llvm/lib/Object/Archive.cpp
@@ -181,7 +181,12 @@ Archive::Child::getAsBinary(LLVMContext *Context) const {
ErrorOr<std::unique_ptr<MemoryBuffer>> BuffOrErr = getMemoryBuffer();
if (std::error_code EC = BuffOrErr.getError())
return EC;
- return createBinary(BuffOrErr.get().release(), Context);
+
+ std::unique_ptr<MemoryBuffer> Buff(BuffOrErr.get().release());
+ ErrorOr<std::unique_ptr<Binary>> Ret = createBinary(Buff.get(), Context);
+ if (!Ret.getError())
+ Buff.release();
+ return Ret;
}
ErrorOr<Archive*> Archive::create(MemoryBuffer *Source) {
OpenPOWER on IntegriCloud