diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2020-02-04 16:36:59 +0100 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2020-02-04 16:36:59 +0100 |
commit | 1b92af1343c87567f00c095a420dc2ce8add9d91 (patch) | |
tree | 695472c982844c199bccdbc5e8d6f44c28ce757e /src | |
parent | 233490819ca4010d0db70a0ae411ae9f73571baa (diff) | |
download | libuv-1b92af1343c87567f00c095a420dc2ce8add9d91.tar.gz libuv-1b92af1343c87567f00c095a420dc2ce8add9d91.zip |
unix: fix error handling in uv__make_pipe()
This commit checks that setting the close-on-exec and non-blocking flags
on the file descriptors succeeds, and closes the file descriptors when
it fails.
PR-URL: https://github.com/libuv/libuv/pull/2665
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/unix/process.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/unix/process.c b/src/unix/process.c index d0d01a9e..b021aaeb 100644 --- a/src/unix/process.c +++ b/src/unix/process.c @@ -149,15 +149,26 @@ int uv__make_pipe(int fds[2], int flags) { if (pipe(fds)) return UV__ERR(errno); - uv__cloexec(fds[0], 1); - uv__cloexec(fds[1], 1); + if (uv__cloexec(fds[0], 1)) + goto fail; + + if (uv__cloexec(fds[1], 1)) + goto fail; if (flags & UV__F_NONBLOCK) { - uv__nonblock(fds[0], 1); - uv__nonblock(fds[1], 1); + if (uv__nonblock(fds[0], 1)) + goto fail; + + if (uv__nonblock(fds[1], 1)) + goto fail; } return 0; + +fail: + uv__close(fds[0]); + uv__close(fds[1]); + return UV__ERR(errno); #endif } |