8187450: JNI local refs exceeds capacity warning in NetworkInterface::getAll

Reviewed-by: chegar, dfuchs, aph
This commit is contained in:
Jonathan Dowland 2021-03-22 15:29:47 +00:00 committed by Chris Hegarty
parent 0abbfb2fc5
commit ba504fcee8
3 changed files with 22 additions and 2 deletions
src/java.base
unix/native/libnet
windows/native/libnet
test/jdk/java/net/NetworkInterface

@ -503,6 +503,7 @@ JNIEXPORT jobjectArray JNICALL Java_java_net_NetworkInterface_getAll
// put the NetworkInterface into the array
(*env)->SetObjectArrayElement(env, netIFArr, arr_index++, netifObj);
(*env)->DeleteLocalRef(env, netifObj);
curr = curr->next;
}
@ -766,12 +767,14 @@ static jobject createNetworkInterface(JNIEnv *env, netif *ifs) {
((struct sockaddr_in*)addrP->brdcast)->sin_addr.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
(*env)->SetObjectField(env, ibObj, ni_ib4broadcastID, ia2Obj);
(*env)->DeleteLocalRef(env, ia2Obj);
} else {
return NULL;
}
}
(*env)->SetShortField(env, ibObj, ni_ib4maskID, addrP->mask);
(*env)->SetObjectArrayElement(env, bindArr, bind_index++, ibObj);
(*env)->DeleteLocalRef(env, ibObj);
} else {
return NULL;
}
@ -800,12 +803,14 @@ static jobject createNetworkInterface(JNIEnv *env, netif *ifs) {
(*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
(*env)->SetShortField(env, ibObj, ni_ib4maskID, addrP->mask);
(*env)->SetObjectArrayElement(env, bindArr, bind_index++, ibObj);
(*env)->DeleteLocalRef(env, ibObj);
} else {
return NULL;
}
}
(*env)->SetObjectArrayElement(env, addrArr, addr_index++, iaObj);
(*env)->DeleteLocalRef(env, iaObj);
addrP = addrP->next;
}
@ -838,6 +843,11 @@ static jobject createNetworkInterface(JNIEnv *env, netif *ifs) {
(*env)->SetObjectField(env, netifObj, ni_bindsID, bindArr);
(*env)->SetObjectField(env, netifObj, ni_childsID, childArr);
(*env)->DeleteLocalRef(env, name);
(*env)->DeleteLocalRef(env, addrArr);
(*env)->DeleteLocalRef(env, bindArr);
(*env)->DeleteLocalRef(env, childArr);
// return the NetworkInterface
return netifObj;
}

@ -641,8 +641,10 @@ jobject createNetworkInterface
return NULL;
}
(*env)->SetObjectField(env, ibObj, ni_ibbroadcastID, ia2Obj);
(*env)->DeleteLocalRef(env, ia2Obj);
(*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
(*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
(*env)->DeleteLocalRef(env, ibObj);
}
} else /* AF_INET6 */ {
int scope;
@ -667,9 +669,11 @@ jobject createNetworkInterface
(*env)->SetObjectField(env, ibObj, ni_ibaddressID, iaObj);
(*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
(*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
(*env)->DeleteLocalRef(env, ibObj);
}
}
(*env)->SetObjectArrayElement(env, addrArr, addr_index, iaObj);
(*env)->DeleteLocalRef(env, iaObj);
addrs = addrs->next;
addr_index++;
}
@ -677,6 +681,10 @@ jobject createNetworkInterface
(*env)->SetObjectField(env, netifObj, ni_bindsID, bindsArr);
free_netaddr(netaddrP);
(*env)->DeleteLocalRef(env, name);
(*env)->DeleteLocalRef(env, displayName);
(*env)->DeleteLocalRef(env, addrArr);
(*env)->DeleteLocalRef(env, bindsArr);
/*
* Windows doesn't have virtual interfaces, so child array
@ -687,6 +695,7 @@ jobject createNetworkInterface
return NULL;
}
(*env)->SetObjectField(env, netifObj, ni_childsID, childArr);
(*env)->DeleteLocalRef(env, childArr);
/* return the NetworkInterface */
return netifObj;
@ -959,6 +968,7 @@ JNIEXPORT jobjectArray JNICALL Java_java_net_NetworkInterface_getAll
/* put the NetworkInterface into the array */
(*env)->SetObjectArrayElement(env, netIFArr, arr_index++, netifObj);
(*env)->DeleteLocalRef(env, netifObj);
curr = curr->next;
}

@ -24,8 +24,8 @@
/* @test
* @bug 4405354 6594296 8058216
* @library /test/lib
* @run main Test
* @run main/othervm -Djava.net.preferIPv4Stack=true Test
* @run main/othervm -Xcheck:jni Test
* @run main/othervm -Xcheck:jni -Djava.net.preferIPv4Stack=true Test
* @summary Basic tests for NetworkInterface
*/
import java.net.NetworkInterface;