]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Fix handling of file descriptors for the files size opens.
authorUlrich Drepper <drepper@redhat.com>
Sat, 24 Jan 2009 00:32:21 +0000 (16:32 -0800)
committerUlrich Drepper <drepper@redhat.com>
Sat, 24 Jan 2009 00:32:21 +0000 (16:32 -0800)
src/ChangeLog
src/size.c

index 30fdb07b72a2ba885fb7cb56b834aa83efd1a485..6203f712a2d35320dfcfe636c03d7e7a150c0d51 100644 (file)
@@ -1,5 +1,9 @@
 2009-01-23  Ulrich Drepper  <drepper@redhat.com>
 
+       * size.c (process_file): When handling archive, close file descriptor
+       here.  For unknown file format also close file descriptor.
+       (handle_ar): Don't close file descriptor here.
+
        * readelf.c (parse_opt): Move code to add to dump_data_sections and
        string_sections list in local function add_dump_section.  Adjust 'x'
        key handling.  For 'a' key add .strtab, .dynstr, and .comment section
index f6f23d55f223a5546d20c8bb7ceed0614a493f4f..4698c350fcbb4d8a0c02ad7a79a00b388d1d7568 100644 (file)
@@ -319,13 +319,23 @@ process_file (const char *fname)
          return 0;
        }
       else if (likely (elf_kind (elf) == ELF_K_AR))
-       return handle_ar (fd, elf, NULL, fname);
+       {
+         int result = handle_ar (fd, elf, NULL, fname);
+
+         if (unlikely  (close (fd) != 0))
+           error (EXIT_FAILURE, errno, gettext ("while closing '%s'"), fname);
+
+         return result;
+       }
 
       /* We cannot handle this type.  Close the descriptor anyway.  */
       if (unlikely (elf_end (elf) != 0))
        INTERNAL_ERROR (fname);
     }
 
+  if (unlikely (close (fd) != 0))
+    error (EXIT_FAILURE, errno, gettext ("while closing '%s'"), fname);
+
   error (0, 0, gettext ("%s: file format not recognized"), fname);
 
   return 1;
@@ -396,9 +406,6 @@ handle_ar (int fd, Elf *elf, const char *prefix, const char *fname)
   if (unlikely (elf_end (elf) != 0))
     INTERNAL_ERROR (fname);
 
-  if (unlikely  (close (fd) != 0))
-    error (EXIT_FAILURE, errno, gettext ("while closing '%s'"), fname);
-
   return result;
 }