From 467df2ad33dee4f5640c1451d2db645c19641a71 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 29 Sep 2015 09:42:03 +0200 Subject: [PATCH] Don't leak socket on setsockopt() errors --- common/network/TcpSocket.cxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx index f51873c1..9ac1478c 100644 --- a/common/network/TcpSocket.cxx +++ b/common/network/TcpSocket.cxx @@ -443,8 +443,11 @@ TcpListener::TcpListener(const struct sockaddr *listenaddr, memcpy (&sa, listenaddr, listenaddrlen); #ifdef IPV6_V6ONLY if (listenaddr->sa_family == AF_INET6) { - if (setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&one, sizeof(one))) - throw SocketException("unable to set IPV6_V6ONLY", errorNumber); + if (setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&one, sizeof(one))) { + int e = errorNumber; + closesocket(sock); + throw SocketException("unable to set IPV6_V6ONLY", e); + } } #endif /* defined(IPV6_V6ONLY) */ -- 2.39.5