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

Commit 11d8011

Browse files
committed
unix: don't close inherited fds on uv_spawn() fail
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.
1 parent fc3a21f commit 11d8011

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/unix/process.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ int uv__make_pipe(int fds[2], int flags) {
186186

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

466466
if (pipes != NULL) {
467467
for (i = 0; i < stdio_count; i++) {
468-
close(pipes[i][0]);
469-
close(pipes[i][1]);
468+
if (i < options.stdio_count)
469+
if (options.stdio[i].flags & (UV_INHERIT_FD | UV_INHERIT_STREAM))
470+
continue;
471+
if (pipes[i][0] != -1)
472+
close(pipes[i][0]);
473+
if (pipes[i][1] != -1)
474+
close(pipes[i][1]);
470475
}
471476
free(pipes);
472477
}

0 commit comments

Comments
 (0)