summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2019-07-28 18:04:46 -0700
committerH. Peter Anvin <hpa@zytor.com>2019-07-28 18:04:46 -0700
commitf3ec9311a824de504d2ff8960d565d0e6cb28b0a (patch)
tree5c88e2b372c982625eb27708d652f2d521d21b50
parent1d9ec2b811ed0d4f269ad24f2cb14e226202d742 (diff)
downloadsamples-f3ec9311a824de504d2ff8960d565d0e6cb28b0a.tar.gz
samples-f3ec9311a824de504d2ff8960d565d0e6cb28b0a.tar.xz
samples-f3ec9311a824de504d2ff8960d565d0e6cb28b0a.zip
file.c: fix writing to a non-mappable file
Correctly handle the case where the output file can't be mapped and we need to fall back to stdio. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--elf2exe/file.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/elf2exe/file.c b/elf2exe/file.c
index ba3ac03..12f2b46 100644
--- a/elf2exe/file.c
+++ b/elf2exe/file.c
@@ -110,7 +110,7 @@ static int map_file_stdio(struct fileinfo *fileinfo)
void *map = NULL;
if (for_write) {
- fileinfo->rd = fileinfo->wr = calloc(fileinfo->size, 1);
+ fileinfo->rd = fileinfo->wr = map = calloc(fileinfo->size, 1);
if (!map)
goto err;
} else {
@@ -133,8 +133,8 @@ static int map_file_stdio(struct fileinfo *fileinfo)
return 0;
err:
- if (fileinfo->rd)
- free((void *)fileinfo->rd);
+ if (map)
+ free(map);
return -1;
}