8012923: [parfait] File Descriptor Leak in jdk/src/windows/demo/jvmti/hprof/hprof_md.c
authorallwin
Mon, 30 Sep 2013 14:28:53 +0200
changeset 20484 5ded5b92c173
parent 20483 dc2362a13fe9
child 20485 8af87f3d549c
8012923: [parfait] File Descriptor Leak in jdk/src/windows/demo/jvmti/hprof/hprof_md.c Reviewed-by: chegar, sla, sspitsyn, mgronlun
jdk/src/windows/demo/jvmti/hprof/hprof_md.c
--- a/jdk/src/windows/demo/jvmti/hprof/hprof_md.c	Mon Sep 30 12:58:18 2013 +0200
+++ b/jdk/src/windows/demo/jvmti/hprof/hprof_md.c	Mon Sep 30 14:28:53 2013 +0200
@@ -82,9 +82,6 @@
     struct sockaddr_in s;
     int fd;
 
-    /* create a socket */
-    fd = (int)socket(AF_INET, SOCK_STREAM, 0);
-
     /* find remote host's addr from name */
     if ((hentry = gethostbyname(hostname)) == NULL) {
         return -1;
@@ -97,8 +94,15 @@
     s.sin_port = htons(port);
     s.sin_family = AF_INET;
 
+    /* create a socket */
+    fd = (int)socket(AF_INET, SOCK_STREAM, 0);
+    if (INVALID_SOCKET == fd) {
+        return 0;
+    }
+
     /* now try connecting */
-    if (-1 == connect(fd, (struct sockaddr*)&s, sizeof(s))) {
+    if (SOCKET_ERROR == connect(fd, (struct sockaddr*)&s, sizeof(s))) {
+        closesocket(fd);
         return 0;
     }
     return fd;