[llvm-commits] [llvm] r64002 - /llvm/trunk/tools/gold/gold-plugin.cpp

Nick Lewycky nicholas at mxc.ca
Fri Feb 6 19:15:01 PST 2009


Author: nicholas
Date: Fri Feb  6 21:15:01 2009
New Revision: 64002

URL: http://llvm.org/viewvc/llvm-project?rev=64002&view=rev
Log:
Free the buffer in the case where we don't create a module out of it, as
pointed out by Torok Edwin.

Remove trailing whitespaces.

Modified:
    llvm/trunk/tools/gold/gold-plugin.cpp

Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=64002&r1=64001&r2=64002&view=diff

==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Fri Feb  6 21:15:01 2009
@@ -161,7 +161,7 @@
     // Gold has found what might be IR part-way inside of a file, such as
     // an .a archive.
     if (lseek(file->fd, file->offset, SEEK_SET) == -1) {
-      (*message)(LDPL_ERROR, 
+      (*message)(LDPL_ERROR,
                  "Failed to seek to archive member of %s at offset %d: %s\n", 
                  file->name,
                  file->offset, strerror(errno));
@@ -169,21 +169,24 @@
     }
     buf = malloc(file->filesize);
     if (!buf) {
-      (*message)(LDPL_ERROR, 
+      (*message)(LDPL_ERROR,
                  "Failed to allocate buffer for archive member of size: %d\n", 
                  file->filesize);
       return LDPS_ERR;
     }
     if (read(file->fd, buf, file->filesize) != file->filesize) {
-      (*message)(LDPL_ERROR, 
-                 "Failed to read archive member of %s at offset %d: %s\n", 
+      (*message)(LDPL_ERROR,
+                 "Failed to read archive member of %s at offset %d: %s\n",
                  file->name,
-                 file->offset,           
+                 file->offset,
                  strerror(errno));
+      free(buf);
       return LDPS_ERR;
     }
-    if (!lto_module_is_object_file_in_memory(buf, file->filesize))
+    if (!lto_module_is_object_file_in_memory(buf, file->filesize)) {
+      free(buf);
       return LDPS_OK;
+    }
   } else if (!lto_module_is_object_file(file->name))
     return LDPS_OK;
 





More information about the llvm-commits mailing list