diff options
author | Ricardo Mestre <mestre@cvs.openbsd.org> | 2016-12-14 08:22:40 +0000 |
---|---|---|
committer | Ricardo Mestre <mestre@cvs.openbsd.org> | 2016-12-14 08:22:40 +0000 |
commit | 06c40f2d537769c94446c56fe6df7b5cf9e83de9 (patch) | |
tree | 271a2d557472f7edc11dd53a5a87c9e50cf7f972 /usr.sbin/unbound | |
parent | 77c00ede9f8b93045be0196a52f3340b620afa00 (diff) |
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()
Diffstat (limited to 'usr.sbin/unbound')
-rw-r--r-- | usr.sbin/unbound/services/listen_dnsport.c | 17 |
1 files changed, 13 insertions, 4 deletions
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"); |