authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-09-22 10:48:42-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-09-22 10:48:42-04:00
log4b902b44a244e29106637f9777aa71b1cd4c22d2
tree16fe00e22ab942fd886f81f5d9396dc24490803f
parentc64f6f950343aef3c6d8fbffcff3ff4fc76960f4

os: fix file descriptor leak in os_exec

See #182

1 files changed, 8 insertions(+), 2 deletions(-)

src/os.cpp+8-2
...@@ -263,6 +263,7 @@ static int os_exec_process_posix(const char *exe, ZigList<const char *> &args,...@@ -263,6 +263,7 @@ static int os_exec_process_posix(const char *exe, ZigList<const char *> &args,
263 } else {263 } else {
264 // parent264 // parent
265 close(stdin_pipe[0]);265 close(stdin_pipe[0]);
266 close(stdin_pipe[1]);
266 close(stdout_pipe[1]);267 close(stdout_pipe[1]);
267 close(stderr_pipe[1]);268 close(stderr_pipe[1]);
268269
...@@ -270,8 +271,13 @@ static int os_exec_process_posix(const char *exe, ZigList<const char *> &args,...@@ -270,8 +271,13 @@ static int os_exec_process_posix(const char *exe, ZigList<const char *> &args,
270 waitpid(pid, &status, 0);271 waitpid(pid, &status, 0);
271 populate_termination(term, status);272 populate_termination(term, status);
272273
273 os_fetch_file(fdopen(stdout_pipe[0], "rb"), out_stdout);274 FILE *stdout_f = fdopen(stdout_pipe[0], "rb");
274 os_fetch_file(fdopen(stderr_pipe[0], "rb"), out_stderr);275 FILE *stderr_f = fdopen(stderr_pipe[0], "rb");
276 os_fetch_file(stdout_f, out_stdout);
277 os_fetch_file(stderr_f, out_stderr);
278
279 fclose(stdout_f);
280 fclose(stderr_f);
275281
276 return 0;282 return 0;
277 }283 }