summaryrefslogtreecommitdiffstats
path: root/binutils/objdump.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2012-02-20 03:25:21 +0000
committerAlan Modra <amodra@gmail.com>2012-02-20 03:25:21 +0000
commit6c7130122d2029f0ab372d3dbb3996769b892fdd (patch)
tree402d97e8396a9b1ea59abd7f27ff246a83e507c2 /binutils/objdump.c
parentfbe2ec189e66302995b66836623c5ae4134aaba7 (diff)
downloadppe42-binutils-6c7130122d2029f0ab372d3dbb3996769b892fdd.tar.gz
ppe42-binutils-6c7130122d2029f0ab372d3dbb3996769b892fdd.zip
* objdump.c (slurp_file): Close file if fstat fails.
Diffstat (limited to 'binutils/objdump.c')
-rw-r--r--binutils/objdump.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/binutils/objdump.c b/binutils/objdump.c
index 76ca2db726..f55b79d645 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
OpenPOWER on IntegriCloud