summaryrefslogtreecommitdiff
path: root/binutils/objdump.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@bigpond.net.au>2012-02-20 03:25:20 +0000
committerAlan Modra <amodra@bigpond.net.au>2012-02-20 03:25:20 +0000
commit6b588a28b1a01e908c07540b1b8138e4c33e8ade (patch)
tree5967871d87c0fc4246dc70fcc0250a5bbd2da5dd /binutils/objdump.c
parent16462cec50da2d070bd7d41fc4092a6abb469953 (diff)
downloadbinutils-redhat-6b588a28b1a01e908c07540b1b8138e4c33e8ade.tar.gz
* 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