From e11dcd4377185359874e67f4962995fdb7e83d19 Mon Sep 17 00:00:00 2001 From: Marc Schlaich Date: Mon, 8 May 2017 12:06:07 +0200 Subject: [PATCH] unix: do not close udp sockets on bind error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes Unix behave in the same way as Windows. Fixes: https://github.com/libuv/libuv/issues/1336 PR-URL: https://github.com/libuv/libuv/pull/1337 Reviewed-By: Colin Ihrig Reviewed-By: Saúl Ibarra Corretgé Reviewed-By: Santiago Gimeno --- src/unix/udp.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/unix/udp.c b/src/unix/udp.c index 73f2bc4e..c556325d 100644 --- a/src/unix/udp.c +++ b/src/unix/udp.c @@ -307,7 +307,7 @@ int uv__udp_bind(uv_udp_t* handle, if (flags & UV_UDP_REUSEADDR) { err = uv__set_reuse(fd); if (err) - goto out; + return err; } if (flags & UV_UDP_IPV6ONLY) { @@ -315,11 +315,11 @@ int uv__udp_bind(uv_udp_t* handle, yes = 1; if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof yes) == -1) { err = -errno; - goto out; + return err; } #else err = -ENOTSUP; - goto out; + return err; #endif } @@ -329,20 +329,14 @@ int uv__udp_bind(uv_udp_t* handle, /* OSX, other BSDs and SunoS fail with EAFNOSUPPORT when binding a * socket created with AF_INET to an AF_INET6 address or vice versa. */ err = -EINVAL; - goto out; + return err; } if (addr->sa_family == AF_INET6) handle->flags |= UV_HANDLE_IPV6; handle->flags |= UV_HANDLE_BOUND; - return 0; - -out: - uv__close(handle->io_watcher.fd); - handle->io_watcher.fd = -1; - return err; }