8157811: Additional minor fixes and cleanups in Networking native code
authorchegar
Wed, 25 May 2016 20:04:57 +0100
changeset 38563 3ab5f00bd5a3
parent 38562 51a7629b68cf
child 38566 6a1386b76fdd
8157811: Additional minor fixes and cleanups in Networking native code Reviewed-by: alanb, clanger, dsamersoff, msheppar
jdk/src/java.base/unix/native/libnet/Inet6AddressImpl.c
jdk/src/java.base/unix/native/libnet/NetworkInterface.c
jdk/src/java.base/unix/native/libnet/net_util_md.c
--- a/jdk/src/java.base/unix/native/libnet/Inet6AddressImpl.c	Wed May 25 20:00:20 2016 +0100
+++ b/jdk/src/java.base/unix/native/libnet/Inet6AddressImpl.c	Wed May 25 20:04:57 2016 +0100
@@ -158,7 +158,10 @@
     }
 
     name = (*env)->NewStringUTF(env, hostname);
-    CHECK_NULL_RETURN(name, NULL);
+    if (name == NULL) {
+        freeifaddrs(ifa);
+        return NULL;
+    }
 
     /* Iterate over the interfaces, and total up the number of IPv4 and IPv6
      * addresses we have. Also keep a count of loopback addresses. We need to
--- a/jdk/src/java.base/unix/native/libnet/NetworkInterface.c	Wed May 25 20:00:20 2016 +0100
+++ b/jdk/src/java.base/unix/native/libnet/NetworkInterface.c	Wed May 25 20:04:57 2016 +0100
@@ -243,6 +243,7 @@
     if (name_utf == NULL) {
        if (!(*env)->ExceptionCheck(env))
            JNU_ThrowOutOfMemoryError(env, NULL);
+       freeif(ifs);
        return NULL;
     }
 
@@ -519,7 +520,7 @@
     }
     if ((sock = openSocketWithFallback(env, name_utf)) < 0) {
        (*env)->ReleaseStringUTFChars(env, name, name_utf);
-       return JNI_FALSE;
+       return NULL;
     }
 
     if (!IS_NULL(addrArray)) {
@@ -664,7 +665,7 @@
     }
 
     // Create the array of InetAddresses
-    addrArr = (*env)->NewObjectArray(env, addr_count,  ia_class, NULL);
+    addrArr = (*env)->NewObjectArray(env, addr_count, ia_class, NULL);
     if (addrArr == NULL) {
         return NULL;
     }
@@ -1829,7 +1830,7 @@
     strncpy(if2.lifr_name, ifname, sizeof(if2.lifr_name) - 1);
 
     if (ioctl(sock, SIOCGLIFFLAGS, (char *)&if2) < 0) {
-         return -1;
+        return -1;
     }
 
     *flags = if2.lifr_flags;
@@ -1859,8 +1860,7 @@
                                               "IPV6 Socket creation failed");
                  return -1;
               }
-         }
-         else{ // errno is not NOSUPPORT
+         } else { // errno is not NOSUPPORT
              NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
                                           "IPV4 Socket creation failed");
              return -1;
--- a/jdk/src/java.base/unix/native/libnet/net_util_md.c	Wed May 25 20:00:20 2016 +0100
+++ b/jdk/src/java.base/unix/native/libnet/net_util_md.c	Wed May 25 20:04:57 2016 +0100
@@ -95,8 +95,8 @@
         CHECK_NULL(c);
         c = (*env)->NewGlobalRef(env, c);
         CHECK_NULL(c);
-        ni_defaultIndexID = (*env)->GetStaticFieldID(
-            env, c, "defaultIndex", "I");
+        ni_defaultIndexID = (*env)->GetStaticFieldID(env, c, "defaultIndex", "I");
+        CHECK_NULL(ni_defaultIndexID);
         ni_class = c;
     }
     int defaultIndex;
@@ -118,8 +118,8 @@
         CHECK_NULL_RETURN(c, 0);
         c = (*env)->NewGlobalRef(env, c);
         CHECK_NULL_RETURN(c, 0);
-        ni_defaultIndexID = (*env)->GetStaticFieldID(env, c,
-                                                     "defaultIndex", "I");
+        ni_defaultIndexID = (*env)->GetStaticFieldID(env, c, "defaultIndex", "I");
+        CHECK_NULL_RETURN(ni_defaultIndexID, 0);
         ni_class = c;
     }
     defaultIndex = (*env)->GetStaticIntField(env, ni_class,