readelf: Fix fd leak on bad input files.
authorRoland McGrath <roland@redhat.com>
Sat, 27 Feb 2010 01:57:50 +0000 (17:57 -0800)
committerRoland McGrath <roland@redhat.com>
Sat, 27 Feb 2010 01:57:50 +0000 (17:57 -0800)
src/ChangeLog
src/readelf.c

index 0b7c51a..4349f3d 100644 (file)
@@ -1,3 +1,7 @@
+2010-02-26  Roland McGrath  <roland@redhat.com>
+
+       * readelf.c (process_file): Don't leak an fd in failure case.
+
 2010-02-15  Roland McGrath  <roland@redhat.com>
 
        * Makefile.am: Use config/eu.am for common stuff.
index 7b3c4f8..682fd55 100644 (file)
@@ -570,13 +570,14 @@ process_file (int fd, const char *fname, bool only_one)
   if (dwfl_report_offline (dwfl, fname, fname, dwfl_fd) == NULL)
     {
       struct stat64 st;
-      if (fstat64 (fd, &st) != 0)
+      if (fstat64 (dwfl_fd, &st) != 0)
        error (0, errno, gettext ("cannot stat input file"));
       else if (unlikely (st.st_size == 0))
        error (0, 0, gettext ("input file is empty"));
       else
        error (0, 0, gettext ("failed reading '%s': %s"),
               fname, dwfl_errmsg (-1));
+      close (dwfl_fd);         /* Consumed on success, not on failure.  */
     }
   else
     {