[llvm] r187039 - Delete the buffer in createObjectFile if it fails.

Rafael Espindola rafael.espindola at gmail.com
Wed Jul 24 07:00:26 PDT 2013


Author: rafael
Date: Wed Jul 24 09:00:26 2013
New Revision: 187039

URL: http://llvm.org/viewvc/llvm-project?rev=187039&view=rev
Log:
Delete the buffer in createObjectFile if it fails.

The Binary constructor takes ownership of the memory buffer. This is a fairly
unfortunate interface, but for now make createObjectFile consistent with it
by also deleting the buffer if it fails.

Fixes a leak in llvm-ar found by the valgrind bots.

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

Modified: llvm/trunk/lib/Object/ObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ObjectFile.cpp?rev=187039&r1=187038&r2=187039&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/ObjectFile.cpp Wed Jul 24 09:00:26 2013
@@ -38,8 +38,10 @@ section_iterator ObjectFile::getRelocate
 }
 
 ObjectFile *ObjectFile::createObjectFile(MemoryBuffer *Object) {
-  if (!Object || Object->getBufferSize() < 64)
+  if (Object->getBufferSize() < 64) {
+    delete Object;
     return 0;
+  }
 
   sys::fs::file_magic Type = sys::fs::identify_magic(Object->getBuffer());
   switch (Type) {
@@ -47,6 +49,7 @@ ObjectFile *ObjectFile::createObjectFile
   case sys::fs::file_magic::bitcode:
   case sys::fs::file_magic::archive:
   case sys::fs::file_magic::macho_universal_binary:
+    delete Object;
     return 0;
   case sys::fs::file_magic::elf_relocatable:
   case sys::fs::file_magic::elf_executable:





More information about the llvm-commits mailing list