OSDN Git Service

Fix for excessive GREF use in gethostbyaddr.
authorUrs Grob <ursg@google.com>
Mon, 27 Apr 2009 10:53:09 +0000 (12:53 +0200)
committerUrs Grob <ursg@google.com>
Mon, 27 Apr 2009 10:53:09 +0000 (12:53 +0200)
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

index cf026bc..0eb2753 100644 (file)
@@ -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;