Skip to content
Permalink
Browse files
8187450: JNI local refs exceeds capacity warning in NetworkInterface:…
…:getAll

Reviewed-by: chegar, dfuchs, aph
  • Loading branch information
Jonathan Dowland authored and ChrisHegarty committed Mar 22, 2021
1 parent 0abbfb2 commit ba504fcee8ba9ca3e6c223effc46754444a9c49f
Showing 3 changed files with 22 additions and 2 deletions.
@@ -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,16 +669,22 @@ 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++;
}
(*env)->SetObjectField(env, netifObj, ni_addrsID, addrArr);
(*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;

0 comments on commit ba504fc

Please sign in to comment.