summaryrefslogtreecommitdiff
path: root/src/logic
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2015-11-23 01:12:26 -0500
committermidipix <writeonce@midipix.org>2016-11-10 23:35:26 -0500
commitb46e6f435a522bc95e353493c1da3e421d5445be (patch)
tree18fe3f903de0f791c20e69644ce6b1305ad29e2d /src/logic
parent2699a2c19915973ed75b1c437fd4554ccf99979e (diff)
downloadperk-b46e6f435a522bc95e353493c1da3e421d5445be.tar.bz2
perk-b46e6f435a522bc95e353493c1da3e421d5445be.tar.xz
pe_map_raw_image(): close fd as needed upon stat failure.
Diffstat (limited to 'src/logic')
-rw-r--r--src/logic/pe_map_raw_image.c9
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;