From f2931ca22c6307a8740f2ec61795f7cfa6971262 Mon Sep 17 00:00:00 2001 From: Urs Grob Date: Mon, 27 Apr 2009 12:53:09 +0200 Subject: [PATCH] Fix for excessive GREF use in gethostbyaddr. Each call to gethostbyaddr in java_net_InetAddress.cpp increases the GREF by one. After calling the method around 1800 times the vm crashes because of excessive global references. --- libcore/luni/src/main/native/java_net_InetAddress.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libcore/luni/src/main/native/java_net_InetAddress.cpp b/libcore/luni/src/main/native/java_net_InetAddress.cpp index cf026bc5b..0eb2753c9 100644 --- a/libcore/luni/src/main/native/java_net_InetAddress.cpp +++ b/libcore/luni/src/main/native/java_net_InetAddress.cpp @@ -258,14 +258,17 @@ static jstring InetAddress_gethostbyaddr(JNIEnv* env, jobject obj, memset(sin, 0, sizeof(struct sockaddr_in)); sin->sin_family = AF_INET; memcpy(&sin->sin_addr.s_addr, rawAddress, 4); + env->ReleaseByteArrayElements(javaAddress, rawAddress, JNI_ABORT); break; case 16: socklen = sizeof(struct sockaddr_in6); memset(sin6, 0, sizeof(struct sockaddr_in6)); sin6->sin6_family = AF_INET6; memcpy(&sin6->sin6_addr.s6_addr, rawAddress, 4); + env->ReleaseByteArrayElements(javaAddress, rawAddress, JNI_ABORT); break; default: + env->ReleaseByteArrayElements(javaAddress, rawAddress, JNI_ABORT); jniThrowException(env, "java/net/UnknownHostException", "Invalid address length"); return NULL; -- 2.11.0