diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2013-08-03 22:16:37 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2013-08-03 22:16:37 +0000 |
commit | 782fdcefa50925f4a42159ae72552220c36fb24e (patch) | |
tree | 8d481bb8e2806bf1b317dccb37b8fa82a2c06870 /lib/Object | |
parent | a757e936263d0a95cbacff4fedd4703e5185800c (diff) | |
download | external_llvm-782fdcefa50925f4a42159ae72552220c36fb24e.zip external_llvm-782fdcefa50925f4a42159ae72552220c36fb24e.tar.gz external_llvm-782fdcefa50925f4a42159ae72552220c36fb24e.tar.bz2 |
MachObjectFile: Don't leak on error.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187698 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Object')
-rw-r--r-- | lib/Object/MachOObjectFile.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 19c8421..5d0399e 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -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 |