diff options
author | Steve Block <steveblock@google.com> | 2011-07-06 12:57:47 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-09-01 09:59:54 +0100 |
commit | 698a253f5568db010beb93b2255697997d180406 (patch) | |
tree | 6ea5fe5addd32b1e111f44fac420585d2f5356f2 /Source/WebCore/bridge/jni | |
parent | 24a08199b7204cfa19c1f61d93ea8df86d3bb99f (diff) | |
download | external_webkit-698a253f5568db010beb93b2255697997d180406.zip external_webkit-698a253f5568db010beb93b2255697997d180406.tar.gz external_webkit-698a253f5568db010beb93b2255697997d180406.tar.bz2 |
Fix some leaked JNI local references in the Java Bridge
This includes a cherry-pick of http://trac.webkit.org/changeset/92689
Bug: 5244518
Change-Id: I38704f2307ab667ee6019fb096265609e27618cc
Diffstat (limited to 'Source/WebCore/bridge/jni')
-rw-r--r-- | Source/WebCore/bridge/jni/JavaMethodJobject.cpp | 2 | ||||
-rw-r--r-- | Source/WebCore/bridge/jni/jsc/JavaFieldJSC.cpp | 6 | ||||
-rw-r--r-- | Source/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp | 15 | ||||
-rw-r--r-- | Source/WebCore/bridge/jni/v8/JavaFieldJobjectV8.cpp | 13 |
4 files changed, 25 insertions, 11 deletions
diff --git a/Source/WebCore/bridge/jni/JavaMethodJobject.cpp b/Source/WebCore/bridge/jni/JavaMethodJobject.cpp index 73cae54..01a0b5b 100644 --- a/Source/WebCore/bridge/jni/JavaMethodJobject.cpp +++ b/Source/WebCore/bridge/jni/JavaMethodJobject.cpp @@ -45,7 +45,7 @@ JavaMethodJobject::JavaMethodJobject(JNIEnv* env, jobject aMethod) // Get return type name jstring returnTypeName = 0; if (jobject returnType = callJNIMethod<jobject>(aMethod, "getReturnType", "()Ljava/lang/Class;")) { - returnTypeName = static_cast<jstring>(callJNIMethod<jobject>(returnType, "getName", "()Ljava/lang/String;")); + returnTypeName = static_cast<jstring>(callJNIMethod<jobject>(returnType, "getName", "()Ljava/lang/String;")); if (!returnTypeName) returnTypeName = env->NewStringUTF("<Unknown>"); env->DeleteLocalRef(returnType); diff --git a/Source/WebCore/bridge/jni/jsc/JavaFieldJSC.cpp b/Source/WebCore/bridge/jni/jsc/JavaFieldJSC.cpp index b7c664e..ee18f66 100644 --- a/Source/WebCore/bridge/jni/jsc/JavaFieldJSC.cpp +++ b/Source/WebCore/bridge/jni/jsc/JavaFieldJSC.cpp @@ -44,19 +44,23 @@ JavaField::JavaField(JNIEnv* env, jobject aField) { // Get field type name jstring fieldTypeName = 0; - if (jobject fieldType = callJNIMethod<jobject>(aField, "getType", "()Ljava/lang/Class;")) + jclass fieldType = static_cast<jclass>(callJNIMethod<jobject>(aField, "getType", "()Ljava/lang/Class;")); + if (fieldType) fieldTypeName = static_cast<jstring>(callJNIMethod<jobject>(fieldType, "getName", "()Ljava/lang/String;")); if (!fieldTypeName) fieldTypeName = env->NewStringUTF("<Unknown>"); m_typeClassName = JavaString(env, fieldTypeName); m_type = javaTypeFromClassName(m_typeClassName.utf8()); + env->DeleteLocalRef(fieldType); + env->DeleteLocalRef(fieldTypeName); // Get field name jstring fieldName = static_cast<jstring>(callJNIMethod<jobject>(aField, "getName", "()Ljava/lang/String;")); if (!fieldName) fieldName = env->NewStringUTF("<Unknown>"); m_name = JavaString(env, fieldName); + env->DeleteLocalRef(fieldName); m_field = new JobjectWrapper(aField); } diff --git a/Source/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp b/Source/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp index 0d1a9f2..a731fe1 100644 --- a/Source/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp +++ b/Source/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp @@ -107,7 +107,7 @@ JavaValue convertNPVariantToJavaValue(NPVariant value, const String& javaClass) } env->SetByteArrayRegion(static_cast<jbyteArray>(javaArray), i, 1, &bVal); } - } else if (!strcmp(javaClassName.data(), "[C")) { + } else if (!strcmp(javaClassName.data(), "[C")) { // array of chars javaArray = env->NewCharArray(length); // Now iterate over each element and add to the array. @@ -123,7 +123,7 @@ JavaValue convertNPVariantToJavaValue(NPVariant value, const String& javaClass) } env->SetCharArrayRegion(static_cast<jcharArray>(javaArray), i, 1, &cVal); } - } else if (!strcmp(javaClassName.data(), "[D")) { + } else if (!strcmp(javaClassName.data(), "[D")) { // array of doubles javaArray = env->NewDoubleArray(length); // Now iterate over each element and add to the array. @@ -135,7 +135,7 @@ JavaValue convertNPVariantToJavaValue(NPVariant value, const String& javaClass) env->SetDoubleArrayRegion(static_cast<jdoubleArray>(javaArray), i, 1, &dVal); } } - } else if (!strcmp(javaClassName.data(), "[F")) { + } else if (!strcmp(javaClassName.data(), "[F")) { // array of floats javaArray = env->NewFloatArray(length); // Now iterate over each element and add to the array. @@ -147,7 +147,7 @@ JavaValue convertNPVariantToJavaValue(NPVariant value, const String& javaClass) env->SetFloatArrayRegion(static_cast<jfloatArray>(javaArray), i, 1, &fVal); } } - } else if (!strcmp(javaClassName.data(), "[I")) { + } else if (!strcmp(javaClassName.data(), "[I")) { // array of ints javaArray = env->NewIntArray(length); // Now iterate over each element and add to the array. @@ -162,7 +162,7 @@ JavaValue convertNPVariantToJavaValue(NPVariant value, const String& javaClass) } env->SetIntArrayRegion(static_cast<jintArray>(javaArray), i, 1, &iVal); } - } else if (!strcmp(javaClassName.data(), "[J")) { + } else if (!strcmp(javaClassName.data(), "[J")) { // array of longs javaArray = env->NewLongArray(length); // Now iterate over each element and add to the array. @@ -177,7 +177,7 @@ JavaValue convertNPVariantToJavaValue(NPVariant value, const String& javaClass) } env->SetLongArrayRegion(static_cast<jlongArray>(javaArray), i, 1, &jVal); } - } else if (!strcmp(javaClassName.data(), "[S")) { + } else if (!strcmp(javaClassName.data(), "[S")) { // array of shorts javaArray = env->NewShortArray(length); // Now iterate over each element and add to the array. @@ -192,7 +192,7 @@ JavaValue convertNPVariantToJavaValue(NPVariant value, const String& javaClass) } env->SetShortArrayRegion(static_cast<jshortArray>(javaArray), i, 1, &sVal); } - } else if (!strcmp(javaClassName.data(), "[Z")) { + } else if (!strcmp(javaClassName.data(), "[Z")) { // array of booleans javaArray = env->NewBooleanArray(length); // Now iterate over each element and add to the array. @@ -210,6 +210,7 @@ JavaValue convertNPVariantToJavaValue(NPVariant value, const String& javaClass) } result.m_objectValue = adoptRef(new JavaInstanceJobject(javaArray)); + env->DeleteLocalRef(javaArray); } break; #endif // PLATFORM(ANDROID) diff --git a/Source/WebCore/bridge/jni/v8/JavaFieldJobjectV8.cpp b/Source/WebCore/bridge/jni/v8/JavaFieldJobjectV8.cpp index 0fe5837..fb23cf5 100644 --- a/Source/WebCore/bridge/jni/v8/JavaFieldJobjectV8.cpp +++ b/Source/WebCore/bridge/jni/v8/JavaFieldJobjectV8.cpp @@ -33,14 +33,23 @@ using namespace JSC::Bindings; JavaFieldJobject::JavaFieldJobject(JNIEnv* env, jobject aField) { // Get field type - jobject fieldType = callJNIMethod<jobject>(aField, "getType", "()Ljava/lang/Class;"); - jstring fieldTypeName = static_cast<jstring>(callJNIMethod<jobject>(fieldType, "getName", "()Ljava/lang/String;")); + jstring fieldTypeName = 0; + jclass fieldType = static_cast<jclass>(callJNIMethod<jobject>(aField, "getType", "()Ljava/lang/Class;")); + if (fieldType) + fieldTypeName = static_cast<jstring>(callJNIMethod<jobject>(fieldType, "getName", "()Ljava/lang/String;")); + if (!fieldTypeName) + fieldTypeName = env->NewStringUTF("<Unknown>"); m_typeClassName = JavaString(env, fieldTypeName); m_type = javaTypeFromClassName(m_typeClassName.utf8()); + env->DeleteLocalRef(fieldType); + env->DeleteLocalRef(fieldTypeName); // Get field name jstring fieldName = static_cast<jstring>(callJNIMethod<jobject>(aField, "getName", "()Ljava/lang/String;")); + if (!fieldName) + fieldName = env->NewStringUTF("<Unknown>"); m_name = JavaString(env, fieldName); + env->DeleteLocalRef(fieldName); m_field = new JobjectWrapper(aField); } |