From 06c40f2d537769c94446c56fe6df7b5cf9e83de9 Mon Sep 17 00:00:00 2001 From: Ricardo Mestre Date: Wed, 14 Dec 2016 08:22:40 +0000 Subject: Remove a resource leak by closing the socket in all error cases. The patch was already committed upstream. OK tb@ and sthen@. jca@ has a valid point that the error would be fatal and most likely the socket would not leak, nevertheless create_tcp_accept_sock() close the socket everytime so for clarity apply the same principal here in create_local_accept_sock() --- usr.sbin/unbound/services/listen_dnsport.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/unbound/services/listen_dnsport.c b/usr.sbin/unbound/services/listen_dnsport.c index 3083876eead..b0d2d71d947 100644 --- a/usr.sbin/unbound/services/listen_dnsport.c +++ b/usr.sbin/unbound/services/listen_dnsport.c @@ -698,28 +698,37 @@ create_local_accept_sock(const char *path, int* noproto) /* The socket already exists and cannot be removed */ log_err("Cannot remove old local socket %s (%s)", path, strerror(errno)); - return -1; + goto err; } if (bind(s, (struct sockaddr *)&usock, (socklen_t)sizeof(struct sockaddr_un)) == -1) { log_err("Cannot bind local socket %s (%s)", path, strerror(errno)); - return -1; + goto err; } if (!fd_set_nonblock(s)) { log_err("Cannot set non-blocking mode"); - return -1; + goto err; } if (listen(s, TCP_BACKLOG) == -1) { log_err("can't listen: %s", strerror(errno)); - return -1; + goto err; } (void)noproto; /*unused*/ return s; + +err: +#ifndef USE_WINSOCK + close(s); +#else + closesocket(s); +#endif + return -1; + #else (void)path; log_err("Local sockets are not supported"); -- cgit v1.2.3