diff options
author | dzwdz | 2023-06-08 18:42:51 +0200 |
---|---|---|
committer | dzwdz | 2023-06-08 18:42:51 +0200 |
commit | 8f0c4e62ffeff86148547c968b0743813d70e649 (patch) | |
tree | d02110f560cafdf051fb41b67836154696d1a700 /src | |
parent | c9fd9181700493823d6947af9ab7ec56c20b7f36 (diff) |
libc/exec: don't leak file descriptors
Diffstat (limited to 'src')
-rw-r--r-- | src/user/lib/elfload.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/user/lib/elfload.c b/src/user/lib/elfload.c index 7b92d35..c1a08f8 100644 --- a/src/user/lib/elfload.c +++ b/src/user/lib/elfload.c @@ -10,6 +10,7 @@ #include <elfload.h> void elf_execf(FILE *f, char **argv, char **envp) { + size_t ret; void *buf; long buflen; @@ -20,8 +21,12 @@ void elf_execf(FILE *f, char **argv, char **envp) { // TODO don't read the entire file into memory fseek(f, 0, SEEK_SET); - if (buf && fread(buf, 1, buflen, f)) + if (!buf) return; + ret = fread(buf, buflen, 1, f); + fclose(f); + if (ret == 1) { elf_exec(buf, argv, envp); + } free(buf); } |