diff options
-rw-r--r-- | src/logic/pe_map_raw_image.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/logic/pe_map_raw_image.c b/src/logic/pe_map_raw_image.c index c248ce9..58f914b 100644 --- a/src/logic/pe_map_raw_image.c +++ b/src/logic/pe_map_raw_image.c @@ -12,11 +12,18 @@ int pe_map_raw_image (int fd, const char * path, int prot, struct pe_raw_image * { struct stat stat; bool fnew; + int ret; if (fnew = (fd < 0)) fd = open(path,O_RDONLY | O_CLOEXEC); - if ((fd < 0) || (fstat(fd,&stat) < 0)) + if (fd < 0) + return -1; + + if ((ret = fstat(fd,&stat) < 0) && fnew) + close(fd); + + if (ret < 0) return -1; map->size = stat.st_size; |