changeset 9997:3c0f4b204de5

7010989: Duplicate closure of file descriptors leads to unexpected and incorrect closure of sockets Reviewed-by: chegar
author igerasim
date Tue, 09 Sep 2014 19:02:36 +0400
parents 0a85994e76cb
children a89c75ba7881
files src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c src/windows/native/java/net/TwoStacksPlainSocketImpl.c src/windows/native/java/net/net_util_md.c
diffstat 3 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c	Thu Sep 11 10:47:49 2014 +0200
+++ b/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c	Tue Sep 09 19:02:36 2014 +0400
@@ -489,6 +489,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/src/windows/native/java/net/TwoStacksPlainSocketImpl.c	Thu Sep 11 10:47:49 2014 +0200
+++ b/src/windows/native/java/net/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/src/windows/native/java/net/net_util_md.c	Thu Sep 11 10:47:49 2014 +0200
+++ b/src/windows/native/java/net/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.