From: Pierre Ossman Date: Tue, 29 Sep 2015 07:42:03 +0000 (+0200) Subject: Don't leak socket on setsockopt() errors X-Git-Tag: v1.5.90~24 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=467df2ad33dee4f5640c1451d2db645c19641a71;p=tigervnc.git Don't leak socket on setsockopt() errors --- 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) */