changeset 8267:ede1fd12e0da

8012923: [parfait] File Descriptor Leak in jdk/src/windows/demo/jvmti/hprof/hprof_md.c Reviewed-by: chegar, sla, sspitsyn, mgronlun
author allwin
date Mon, 30 Sep 2013 14:28:53 +0200
parents cceaad499685
children d0de46a2cbd0
files src/windows/demo/jvmti/hprof/hprof_md.c
diffstat 1 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/demo/jvmti/hprof/hprof_md.c	Mon Sep 30 12:58:18 2013 +0200
+++ b/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;