Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix: don't close inherited fds on uv_spawn() fail
Browse files Browse the repository at this point in the history
The cleanup-after-error code path in uv_spawn() was closing file
descriptors indiscriminately.  Only close file descriptors that we
created ourselves, not the ones that are passed in by the user.

Fixes nodejs/node-v0.x-archive#6297.
  • Loading branch information
bnoordhuis committed Oct 2, 2013
1 parent fc3a21f commit 11d8011
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/unix/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ int uv__make_pipe(int fds[2], int flags) {

/*
* Used for initializing stdio streams like options.stdin_stream. Returns
* zero on success.
* zero on success. See also the cleanup section in uv_spawn().
*/
static int uv__process_init_stdio(uv_stdio_container_t* container, int fds[2]) {
int mask;
Expand Down Expand Up @@ -465,8 +465,13 @@ int uv_spawn(uv_loop_t* loop,

if (pipes != NULL) {
for (i = 0; i < stdio_count; i++) {
close(pipes[i][0]);
close(pipes[i][1]);
if (i < options.stdio_count)
if (options.stdio[i].flags & (UV_INHERIT_FD | UV_INHERIT_STREAM))
continue;
if (pipes[i][0] != -1)
close(pipes[i][0]);
if (pipes[i][1] != -1)
close(pipes[i][1]);
}
free(pipes);
}
Expand Down

0 comments on commit 11d8011

Please sign in to comment.