Fix a memory leak in the error path.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211184 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2014-06-18 17:07:15 +00:00
parent debd831223
commit a841620f66

View File

@ -17,8 +17,8 @@
namespace llvm {
using namespace object;
ErrorOr<ObjectFile *> ObjectFile::createELFObjectFile(MemoryBuffer *Obj,
bool BufferOwned) {
static ErrorOr<ObjectFile *> createELFObjectFileAux(MemoryBuffer *Obj,
bool BufferOwned) {
std::pair<unsigned char, unsigned char> Ident = getElfArchType(Obj);
std::size_t MaxAlignment =
1ULL << countTrailingZeros(uintptr_t(Obj->getBufferStart()));
@ -82,4 +82,12 @@ ErrorOr<ObjectFile *> ObjectFile::createELFObjectFile(MemoryBuffer *Obj,
return R.release();
}
ErrorOr<ObjectFile *> ObjectFile::createELFObjectFile(MemoryBuffer *Obj,
bool BufferOwned) {
ErrorOr<ObjectFile *> Ret = createELFObjectFileAux(Obj, BufferOwned);
if (BufferOwned && Ret.getError())
delete Obj;
return Ret;
}
} // end namespace llvm