From 8a2e123abe5bbfc8787035e5b8f77fbccdec113b Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Tue, 31 Oct 2023 12:02:57 -0400 Subject: Close dangling file descriptor * Only remove temporary script file if it exists --- src/system.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/system.c') diff --git a/src/system.c b/src/system.c index ad89682..8cd7303 100644 --- a/src/system.c +++ b/src/system.c @@ -96,6 +96,7 @@ int shell2(struct Process *proc, char *args) { fprintf(tp, "#!/bin/bash\n%s\n", args); fflush(tp); fclose(tp); + close(fd); chmod(t_name, 0755); pid = fork(); @@ -123,6 +124,10 @@ int shell2(struct Process *proc, char *args) { } retval = execl("/bin/bash", "bash", "-c", t_name, (char *) NULL); + if (!access(t_name, F_OK)) { + remove(t_name); + } + if (proc != NULL && strlen(proc->stdout)) { if (fp_out != NULL) { fflush(fp_out); @@ -154,7 +159,9 @@ int shell2(struct Process *proc, char *args) { } } - remove(t_name); + if (!access(t_name, F_OK)) { + remove(t_name); + } if (proc != NULL) { proc->returncode = status; -- cgit