[llvm] r211184 - Fix a memory leak in the error path.

Rafael Espindola rafael.espindola at gmail.com
Wed Jun 18 10:07:15 PDT 2014


Author: rafael
Date: Wed Jun 18 12:07:15 2014
New Revision: 211184

URL: http://llvm.org/viewvc/llvm-project?rev=211184&view=rev
Log:
Fix a memory leak in the error path.

Modified:
    llvm/trunk/lib/Object/ELFObjectFile.cpp

Modified: llvm/trunk/lib/Object/ELFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ELFObjectFile.cpp?rev=211184&r1=211183&r2=211184&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ELFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/ELFObjectFile.cpp Wed Jun 18 12:07:15 2014
@@ -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::create
   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





More information about the llvm-commits mailing list