From 1b92af1343c87567f00c095a420dc2ce8add9d91 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 4 Feb 2020 16:36:59 +0100 Subject: [PATCH] unix: fix error handling in uv__make_pipe() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Saúl Ibarra Corretgé --- src/unix/process.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/unix/process.c b/src/unix/process.c index d0d01a9e6..b021aaeba 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 }