From 79c55f9c9e1b5fb52c8c798e47b0d849e728338c Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 13 Apr 2020 23:28:22 -0700 Subject: open-socket-pair: bugfix. * socket.c (socketpair_wrap): Don't close descriptors unconditionally in unwind case; only if the list to be returned has not been created. --- socket.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'socket.c') diff --git a/socket.c b/socket.c index 35ef7220..7b695573 100644 --- a/socket.c +++ b/socket.c @@ -1047,7 +1047,7 @@ static val socketpair_wrap(val family, val type, val mode_str) { val s0 = open_sockfd(num(sv[0]), family, type, mode_str); - val s1 = open_sockfd(num(sv[1]), family, type, mode_str); + val s1 = open_sockfd(num(sv[1]), family, type, mode_str); sock_mark_connected(s0); sock_mark_connected(s1); @@ -1056,10 +1056,12 @@ static val socketpair_wrap(val family, val type, val mode_str) } uw_unwind { - if (sv[0] != -1) - close(sv[0]); - if (sv[1] != -1) - close(sv[1]); + if (!out) { + if (sv[0] != -1) + close(sv[0]); + if (sv[1] != -1) + close(sv[1]); + } } uw_catch_end; -- cgit v1.2.3