7010989: Duplicate closure of file descriptors leads to unexpected and incorrect closure of sockets
Reviewed-by: chegar
--- a/jdk/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c Tue Sep 09 17:20:26 2014 +0400
+++ b/jdk/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c Tue Sep 09 19:02:36 2014 +0400
@@ -493,6 +493,9 @@
}
}
} else {
+ /* NET_BindV6() closes both sockets upon a failure */
+ (*env)->SetObjectField(env, this, pdsi_fdID, NULL);
+ (*env)->SetObjectField(env, this, pdsi_fd1ID, NULL);
NET_ThrowCurrent (env, "Cannot bind");
return;
}
--- a/jdk/src/java.base/windows/native/libnet/TwoStacksPlainSocketImpl.c Tue Sep 09 17:20:26 2014 +0400
+++ b/jdk/src/java.base/windows/native/libnet/TwoStacksPlainSocketImpl.c Tue Sep 09 19:02:36 2014 +0400
@@ -467,6 +467,10 @@
(*env)->SetIntField(env, fd1Obj, IO_fd_fdID, fd1);
}
}
+ } else {
+ /* NET_BindV6() closes both sockets upon a failure */
+ (*env)->SetObjectField(env, this, psi_fdID, NULL);
+ (*env)->SetObjectField(env, this, psi_fd1ID, NULL);
}
} else {
rv = NET_WinBind(fd, (struct sockaddr *)&him, len, exclBind);
--- a/jdk/src/java.base/windows/native/libnet/net_util_md.c Tue Sep 09 17:20:26 2014 +0400
+++ b/jdk/src/java.base/windows/native/libnet/net_util_md.c Tue Sep 09 19:02:36 2014 +0400
@@ -627,7 +627,7 @@
* and returns SOCKET_ERROR. Used in NET_BindV6 only.
*/
-#define CLOSE_SOCKETS_AND_RETURN { \
+#define CLOSE_SOCKETS_AND_RETURN do { \
if (fd != -1) { \
closesocket (fd); \
fd = -1; \
@@ -646,7 +646,7 @@
} \
b->ipv4_fd = b->ipv6_fd = -1; \
return SOCKET_ERROR; \
-}
+} while(0)
/*
* if ipv6 is available, call NET_BindV6 to bind to the required address/port.