From 06616db3622d97122c161ec4faf6cfbb85a10ab6 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_socketpair() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit checks that setting the close-on-exec flag 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 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/unix/process.c b/src/unix/process.c index a8fd196b..f0c1108e 100644 --- a/src/unix/process.c +++ b/src/unix/process.c @@ -119,11 +119,20 @@ static int uv__make_socketpair(int fds[2]) { return 0; #else + int err; + if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds)) return UV__ERR(errno); - uv__cloexec(fds[0], 1); - uv__cloexec(fds[1], 1); + err = uv__cloexec(fds[0], 1); + if (err == 0) + err = uv__cloexec(fds[1], 1); + + if (err != 0) { + uv__close(fds[0]); + uv__close(fds[1]); + return UV__ERR(errno); + } return 0; #endif