7176138: Fixes for missing close() calls and possible null pointer reference instead of fatal error
authorohair
Tue, 12 Jun 2012 13:54:20 -0700
changeset 13014 e2fe1611bb04
parent 13012 c4ef809d7fca
child 13015 b87f392315f2
7176138: Fixes for missing close() calls and possible null pointer reference instead of fatal error Reviewed-by: dcubed
jdk/src/share/demo/jvmti/hprof/hprof_table.c
jdk/src/solaris/demo/jvmti/hprof/hprof_md.c
--- a/jdk/src/share/demo/jvmti/hprof/hprof_table.c	Mon Jun 11 07:10:48 2012 -0400
+++ b/jdk/src/share/demo/jvmti/hprof/hprof_table.c	Tue Jun 12 13:54:20 2012 -0700
@@ -120,7 +120,7 @@
     TableIndex     table_incr;          /* Suggested increment size. */
     TableIndex     hash_bucket_count;   /* Number of hash buckets. */
     int            elem_size;           /* Size of element. */
-    int            info_size;           /* Size of info structure. */
+    int            info_size;           /* Size of info structure (can be 0). */
     void          *freed_bv;            /* Freed element bit vector */
     int            freed_count;         /* Count of freed'd elements */
     TableIndex     freed_start;         /* First freed in table */
@@ -208,9 +208,6 @@
 {
     TableElement *element;
 
-    if ( ltable->info_size == 0 ) {
-        return NULL;
-    }
     element = (TableElement*)ELEMENT_PTR(ltable,index);
     return element->info;
 }
@@ -760,7 +757,11 @@
                 void *info;
 
                 get_key(ltable, index, &key_ptr, &key_len);
-                info = get_info(ltable, index);
+                if ( ltable->info_size == 0 ) {
+                    info = NULL;
+                } else {
+                    info = get_info(ltable, index);
+                }
                 (*func)(SANITY_ADD_HARE(index, ltable->hare), key_ptr, key_len, info, arg);
                 if ( is_freed_entry(ltable, index) ) {
                     fcount++;
--- a/jdk/src/solaris/demo/jvmti/hprof/hprof_md.c	Mon Jun 11 07:10:48 2012 -0400
+++ b/jdk/src/solaris/demo/jvmti/hprof/hprof_md.c	Tue Jun 12 13:54:20 2012 -0700
@@ -119,9 +119,13 @@
 
     /* create a socket */
     fd = socket(AF_INET, SOCK_STREAM, 0);
+    if ( fd < 0 ) {
+        return -1;
+    }
 
     /* find remote host's addr from name */
     if ((hentry = gethostbyname(hostname)) == NULL) {
+        (void)close(fd);
         return -1;
     }
     (void)memset((char *)&s, 0, sizeof(s));
@@ -134,6 +138,7 @@
 
     /* now try connecting */
     if (-1 == connect(fd, (struct sockaddr*)&s, sizeof(s))) {
+        (void)close(fd);
         return 0;
     }
     return fd;