Index: jni/JniLogSystem.cpp |
diff --git a/jni/JniLogSystem.cpp b/jni/JniLogSystem.cpp |
index 275b5ef85b7d0b56a91ba9a02434448db08de437..f3771e08c274bc2f16bd18281ad3314135a42432 100644 |
--- a/jni/JniLogSystem.cpp |
+++ b/jni/JniLogSystem.cpp |
@@ -40,8 +40,9 @@ void JniLogSystemCallback::operator()(AdblockPlus::LogSystem::LogLevel logLevel, |
{ |
JNIEnvAcquire env(GetJavaVM()); |
- jclass clazz = env->GetObjectClass(GetCallbackObject()); |
- jmethodID method = env->GetMethodID(clazz, "logCallback", "(" TYP("LogSystem$LogLevel") "Ljava/lang/String;Ljava/lang/String;)V"); |
+ jmethodID method = env->GetMethodID( |
+ *JniLocalReference<jclass>(*env, env->GetObjectClass(GetCallbackObject())), |
+ "logCallback", "(" TYP("LogSystem$LogLevel") "Ljava/lang/String;Ljava/lang/String;)V"); |
// TODO: Set log level from Java and handle it here (to reduce C++->Java calls) |
@@ -73,12 +74,12 @@ void JniLogSystemCallback::operator()(AdblockPlus::LogSystem::LogLevel logLevel, |
if (enumClass) |
{ |
jfieldID enumField = env->GetStaticFieldID(enumClass, enumName, TYP("LogSystem$LogLevel")); |
- jobject jLogLevel = env->GetStaticObjectField(enumClass, enumField); |
+ JniLocalReference<jobject> jLogLevel(*env, env->GetStaticObjectField(enumClass, enumField)); |
- jstring jMessage = env->NewStringUTF(message.c_str()); |
- jstring jSource = env->NewStringUTF(source.c_str()); |
+ JniLocalReference<jstring> jMessage(*env, env->NewStringUTF(message.c_str())); |
+ JniLocalReference<jstring> jSource(*env, env->NewStringUTF(source.c_str())); |
- env->CallVoidMethod(GetCallbackObject(), method, jLogLevel, jMessage, jSource); |
+ env->CallVoidMethod(GetCallbackObject(), method, *jLogLevel, *jMessage, *jSource); |
} |
CheckAndLogJavaException(*env); |