From 782fdcefa50925f4a42159ae72552220c36fb24e Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sat, 3 Aug 2013 22:16:37 +0000 Subject: [PATCH] MachObjectFile: Don't leak on error. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187698 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/MachOObjectFile.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 19c842105cf..5d0399ebd4f 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 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