run_interactive(): Fix a potential file descriptor leak.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2014-11-26 23:45:20 +01:00
1 parent 939cfc2476
commit def759fe41
1 file changed
+2 -1
+2 -1
View File
@@ -502,7 +502,7 @@ int run_interactive(char *cmd, char *fmt, ...)
int status, oldout = 1, olderr = 2; int status, oldout = 1, olderr = 2;
char line[LINE_SIZE]; char line[LINE_SIZE];
va_list ap; va_list ap;
FILE *fp = tmpfile(); FILE *fp;
if (!cmd) { if (!cmd) {
errno = EINVAL; errno = EINVAL;
@@ -518,6 +518,7 @@ int run_interactive(char *cmd, char *fmt, ...)
} }
/* Redirect output from cmd to a tempfile */ /* Redirect output from cmd to a tempfile */
fp = tmpfile();
if (fp && !debug) { if (fp && !debug) {
oldout = dup(STDOUT_FILENO); oldout = dup(STDOUT_FILENO);
olderr = dup(STDERR_FILENO); olderr = dup(STDERR_FILENO);