MachObjectFile: Don't leak on error.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187698 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2013-08-03 22:16:37 +00:00
parent a757e93626
commit 782fdcefa5

View File

@ -1599,21 +1599,23 @@ void MachOObjectFile::ReadULEB128s(uint64_t Index,
ObjectFile *ObjectFile::createMachOObjectFile(MemoryBuffer *Buffer) {
StringRef Magic = Buffer->getBuffer().slice(0, 4);
error_code ec;
ObjectFile *Ret;
OwningPtr<ObjectFile> Ret;
if (Magic == "\xFE\xED\xFA\xCE")
Ret = new MachOObjectFile(Buffer, false, false, ec);
Ret.reset(new MachOObjectFile(Buffer, false, false, ec));
else if (Magic == "\xCE\xFA\xED\xFE")
Ret = new MachOObjectFile(Buffer, true, false, ec);
Ret.reset(new MachOObjectFile(Buffer, true, false, ec));
else if (Magic == "\xFE\xED\xFA\xCF")
Ret = new MachOObjectFile(Buffer, false, true, ec);
Ret.reset(new MachOObjectFile(Buffer, false, true, ec));
else if (Magic == "\xCF\xFA\xED\xFE")
Ret = new MachOObjectFile(Buffer, true, true, ec);
else
Ret.reset(new MachOObjectFile(Buffer, true, true, ec));
else {
delete Buffer;
return NULL;
}
if (ec)
return NULL;
return Ret;
return Ret.take();
}
} // end namespace object