diff options
| -rw-r--r-- | src/lib/core/system.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/lib/core/system.c b/src/lib/core/system.c index 6c18cc2..608994e 100644 --- a/src/lib/core/system.c +++ b/src/lib/core/system.c @@ -21,7 +21,12 @@ int shell(struct Process *proc, char *args) { FILE *tp = NULL; char *t_name = xmkstemp(&tp, "w"); - if (!t_name || !tp) { + if (!t_name) { + fclose(tp); + return -1; + } + if (!tp) { + guard_free(t_name); return -1; } @@ -37,6 +42,8 @@ int shell(struct Process *proc, char *args) { pid_t pid = fork(); if (pid == -1) { fprintf(stderr, "fork failed\n"); + guard_free(t_name); + fclose(tp); exit(1); } else if (pid == 0) { FILE *fp_out = NULL; @@ -55,6 +62,9 @@ int shell(struct Process *proc, char *args) { fp_err = freopen(proc->f_stderr, "w+", stderr); if (!fp_err) { fprintf(stderr, "Unable to redirect stderr to %s: %s\n", proc->f_stdout, strerror(errno)); + if (fp_out) { + fclose(fp_out); + } exit(1); } } |
