8157811: Additional minor fixes and cleanups in Networking native code

Reviewed-by: alanb, clanger, dsamersoff, msheppar
This commit is contained in:
Chris Hegarty 2016-05-25 20:04:57 +01:00
parent 28f80af02a
commit c4db92a027
3 changed files with 13 additions and 10 deletions

View File

@ -158,7 +158,10 @@ lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6)
}
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

View File

@ -243,6 +243,7 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByName0
if (name_utf == NULL) {
if (!(*env)->ExceptionCheck(env))
JNU_ThrowOutOfMemoryError(env, NULL);
freeif(ifs);
return NULL;
}
@ -519,7 +520,7 @@ JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0
}
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 @@ jobject createNetworkInterface(JNIEnv *env, netif *ifs) {
}
// 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 @@ static int getFlags(int sock, const char *ifname, int *flags) {
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 @@ static int openSocketWithFallback(JNIEnv *env, const char *ifname) {
"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;

View File

@ -95,8 +95,8 @@ void setDefaultScopeID(JNIEnv *env, struct sockaddr *him)
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 @@ int getDefaultScopeID(JNIEnv *env) {
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,