From: Alan Modra Date: Mon, 20 Feb 2012 03:25:21 +0000 (+0000) Subject: * objdump.c (slurp_file): Close file if fstat fails. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6c7130122d2029f0ab372d3dbb3996769b892fdd;p=binutils-gdb.git * objdump.c (slurp_file): Close file if fstat fails. --- diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 577dd6f815d..a6cc5547ba8 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,7 @@ +2012-02-20 Namhyung Kim + + * objdump.c (slurp_file): Close file if fstat fails. + 2012-02-14 Cary Coutant * dwarf.c (dwarf_vmatoa64): New function. diff --git a/binutils/objdump.c b/binutils/objdump.c index 76ca2db726e..f55b79d6454 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -1123,25 +1123,28 @@ slurp_file (const char *fn, size_t *size) if (fd < 0) return NULL; if (fstat (fd, &st) < 0) - return NULL; + { + close (fd); + return NULL; + } *size = st.st_size; #ifdef HAVE_MMAP msize = (*size + ps - 1) & ~(ps - 1); map = mmap (NULL, msize, PROT_READ, MAP_SHARED, fd, 0); - if (map != (char *)-1L) + if (map != (char *) -1L) { - close(fd); - return map; + close (fd); + return map; } #endif map = (const char *) malloc (*size); - if (!map || (size_t) read (fd, (char *)map, *size) != *size) - { - free ((void *)map); + if (!map || (size_t) read (fd, (char *) map, *size) != *size) + { + free ((void *) map); map = NULL; } close (fd); - return map; + return map; } #define line_map_decrease 5