From b308b106e3f74da8be249ff00f500dd7cc4304ba Mon Sep 17 00:00:00 2001 From: Tobrun Date: Thu, 5 Apr 2018 22:37:45 +0200 Subject: [PATCH] [android] - add delete local refs calls for make jni strings --- platform/android/src/offline/offline_manager.cpp | 8 ++++++-- platform/android/src/offline/offline_region.cpp | 12 +++++++++--- platform/android/src/snapshotter/map_snapshotter.cpp | 4 +++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/platform/android/src/offline/offline_manager.cpp b/platform/android/src/offline/offline_manager.cpp index 02871e7fdf2..4960ae2845d 100644 --- a/platform/android/src/offline/offline_manager.cpp +++ b/platform/android/src/offline/offline_manager.cpp @@ -102,7 +102,9 @@ void OfflineManager::ListOfflineRegionsCallback::onError(jni::JNIEnv& env, std::exception_ptr error) { static auto method = javaClass.GetMethod(env, "onError"); std::string message = mbgl::util::toString(error); - callback.Call(env, method, jni::Make(env, message)); + auto jmessage = jni::Make(env, message); + callback.Call(env, method, jmessage); + jni::DeleteLocalRef(env, jmessage); } void OfflineManager::ListOfflineRegionsCallback::onList(jni::JNIEnv& env, @@ -138,7 +140,9 @@ void OfflineManager::CreateOfflineRegionCallback::onError(jni::JNIEnv& env, std::exception_ptr error) { static auto method = javaClass.GetMethod(env, "onError"); std::string message = mbgl::util::toString(error); - callback.Call(env, method, jni::Make(env, message)); + auto jmessage = jni::Make(env, message); + callback.Call(env, method, jmessage); + jni::DeleteLocalRef(env, jmessage); } void OfflineManager::CreateOfflineRegionCallback::onCreate(jni::JNIEnv& env, diff --git a/platform/android/src/offline/offline_region.cpp b/platform/android/src/offline/offline_region.cpp index 856434d2669..27de76fb003 100644 --- a/platform/android/src/offline/offline_region.cpp +++ b/platform/android/src/offline/offline_region.cpp @@ -239,7 +239,9 @@ void OfflineRegion::OfflineRegionStatusCallback::onError(jni::JNIEnv& env, std::exception_ptr error) { static auto method = javaClass.GetMethod(env, "onError"); std::string message = mbgl::util::toString(error); - callback.Call(env, method, jni::Make(env, message)); + auto jmessage = jni::Make(env, message); + callback.Call(env, method, jmessage); + jni::DeleteLocalRef(env, jmessage); } void OfflineRegion::OfflineRegionStatusCallback::onStatus(jni::JNIEnv& env, @@ -267,7 +269,9 @@ void OfflineRegion::OfflineRegionDeleteCallback::onError(jni::JNIEnv& env, std::exception_ptr error) { static auto method = javaClass.GetMethod(env, "onError"); std::string message = mbgl::util::toString(error); - callback.Call(env, method, jni::Make(env, message)); + auto jmessage = jni::Make(env, message); + callback.Call(env, method, jmessage); + jni::DeleteLocalRef(env, jmessage); } void OfflineRegion::OfflineRegionDeleteCallback::onDelete(jni::JNIEnv& env, jni::Object callback) { @@ -289,7 +293,9 @@ void OfflineRegion::OfflineRegionUpdateMetadataCallback::onError(jni::JNIEnv& en std::exception_ptr error) { static auto method = javaClass.GetMethod(env, "onError"); std::string message = mbgl::util::toString(error); - callback.Call(env, method, jni::Make(env, message)); + auto jmessage = jni::Make(env, message); + callback.Call(env, method, jmessage); + jni::DeleteLocalRef(env, jmessage); } void OfflineRegion::OfflineRegionUpdateMetadataCallback::onUpdate(jni::JNIEnv& env, diff --git a/platform/android/src/snapshotter/map_snapshotter.cpp b/platform/android/src/snapshotter/map_snapshotter.cpp index 71f8b4f4c02..a006953d368 100644 --- a/platform/android/src/snapshotter/map_snapshotter.cpp +++ b/platform/android/src/snapshotter/map_snapshotter.cpp @@ -71,7 +71,9 @@ void MapSnapshotter::start(JNIEnv& env) { if (err) { // error handler callback static auto onSnapshotFailed = javaClass.GetMethod(*_env, "onSnapshotFailed"); - javaPeer->Call(*_env, onSnapshotFailed, jni::Make(*_env, util::toString(err))); + auto message = jni::Make(*_env, util::toString(err)); + javaPeer->Call(*_env, onSnapshotFailed, message); + jni::DeleteLocalRef(*_env, message); } else { // Create the wrapper auto mapSnapshot = android::MapSnapshot::New(*_env, std::move(image), pixelRatio, attributions, showLogo, pointForFn);