]> source.dussan.org Git - tigervnc.git/commitdiff
Don't leak socket on setsockopt() errors
authorPierre Ossman <ossman@cendio.se>
Tue, 29 Sep 2015 07:42:03 +0000 (09:42 +0200)
committerPierre Ossman <ossman@cendio.se>
Tue, 29 Sep 2015 07:42:03 +0000 (09:42 +0200)
common/network/TcpSocket.cxx

index f51873c1a3d952976a94d8118b936746d268d6e4..9ac1478ca8c27cf00a648f8a9ca948cd1fcf536c 100644 (file)
@@ -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) */