diff options
| author | Mai <mai.iam2048@gmail.com> | 2022-12-28 00:57:29 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-28 00:57:29 +0000 |
| commit | 9e9910df8b0c965e1a496d479ad94bc78f918817 (patch) | |
| tree | db34ae4f459b9ab916320ffa39bad007087f369b /Source/Android/jni/MainAndroid.cpp | |
| parent | 1f1474f8aca0f706154faa3be9d4127258463b5c (diff) | |
| parent | b3a368ae06c5f82afdd617355afba388c90d19e8 (diff) | |
Merge pull request #11376 from JosJuice/android-delete-local-ref
Android: Make more meticulous use of DeleteLocalRef
Diffstat (limited to 'Source/Android/jni/MainAndroid.cpp')
| -rw-r--r-- | Source/Android/jni/MainAndroid.cpp | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp index 1e80675d8d..428870d02f 100644 --- a/Source/Android/jni/MainAndroid.cpp +++ b/Source/Android/jni/MainAndroid.cpp @@ -204,11 +204,16 @@ static bool MsgAlert(const char* caption, const char* text, bool yes_no, Common: std::thread([&] { JNIEnv* env = IDCache::GetEnvForThread(); + jstring j_caption = ToJString(env, caption); + jstring j_text = ToJString(env, text); + // Execute the Java method. result = env->CallStaticBooleanMethod( - IDCache::GetNativeLibraryClass(), IDCache::GetDisplayAlertMsg(), ToJString(env, caption), - ToJString(env, text), yes_no, style == Common::MsgType::Warning, - s_need_nonblocking_alert_msg); + IDCache::GetNativeLibraryClass(), IDCache::GetDisplayAlertMsg(), j_caption, j_text, yes_no, + style == Common::MsgType::Warning, s_need_nonblocking_alert_msg); + + env->DeleteLocalRef(j_caption); + env->DeleteLocalRef(j_text); }).join(); return result != JNI_FALSE; @@ -222,20 +227,29 @@ static void ReportSend(const std::string& endpoint, const std::string& report) jbyte* output = env->GetByteArrayElements(output_array, nullptr); memcpy(output, report.data(), report.size()); env->ReleaseByteArrayElements(output_array, output, 0); + + jstring j_endpoint = ToJString(env, endpoint); + env->CallStaticVoidMethod(IDCache::GetAnalyticsClass(), IDCache::GetSendAnalyticsReport(), - ToJString(env, endpoint), output_array); + j_endpoint, output_array); + + env->DeleteLocalRef(output_array); + env->DeleteLocalRef(j_endpoint); } static std::string GetAnalyticValue(const std::string& key) { JNIEnv* env = IDCache::GetEnvForThread(); - auto value = reinterpret_cast<jstring>(env->CallStaticObjectMethod( - IDCache::GetAnalyticsClass(), IDCache::GetAnalyticsValue(), ToJString(env, key))); + jstring j_key = ToJString(env, key); + auto j_value = reinterpret_cast<jstring>(env->CallStaticObjectMethod( + IDCache::GetAnalyticsClass(), IDCache::GetAnalyticsValue(), j_key)); + env->DeleteLocalRef(j_key); - std::string stdvalue = GetJString(env, value); + std::string value = GetJString(env, j_value); + env->DeleteLocalRef(j_value); - return stdvalue; + return value; } extern "C" { @@ -655,8 +669,15 @@ JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetLogTyp env->NewObject(IDCache::GetLinkedHashMapClass(), IDCache::GetLinkedHashMapInit(), map_size); for (const auto& entry : map) { - env->CallObjectMethod(linked_hash_map, IDCache::GetLinkedHashMapPut(), - ToJString(env, entry.first), ToJString(env, entry.second)); + jstring key = ToJString(env, entry.first); + jstring value = ToJString(env, entry.second); + + jobject result = + env->CallObjectMethod(linked_hash_map, IDCache::GetLinkedHashMapPut(), key, value); + + env->DeleteLocalRef(key); + env->DeleteLocalRef(value); + env->DeleteLocalRef(result); } return linked_hash_map; } @@ -693,8 +714,13 @@ JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ConvertD const auto callback = [&jCallbackGlobal](const std::string& text, float completion) { JNIEnv* env = IDCache::GetEnvForThread(); - return static_cast<bool>(env->CallBooleanMethod( - jCallbackGlobal, IDCache::GetCompressCallbackRun(), ToJString(env, text), completion)); + + jstring j_text = ToJString(env, text); + jboolean result = env->CallBooleanMethod(jCallbackGlobal, IDCache::GetCompressCallbackRun(), + j_text, completion); + env->DeleteLocalRef(j_text); + + return static_cast<bool>(result); }; bool success = false; |
