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 joyent/node#6297.
This commit is contained in:
Ben Noordhuis 2013-10-02 11:17:18 +02:00
parent fc3a21f943
commit 11d8011793

View File

@ -186,7 +186,7 @@ skip:
/*
* 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;
@ -465,8 +465,13 @@ error:
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);
}