Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - add delete local refs calls for make jni strings
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Apr 9, 2018
1 parent 14423a2 commit c1dabbd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
8 changes: 6 additions & 2 deletions platform/android/src/offline/offline_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ void OfflineManager::ListOfflineRegionsCallback::onError(jni::JNIEnv& env,
std::exception_ptr error) {
static auto method = javaClass.GetMethod<void (jni::String)>(env, "onError");
std::string message = mbgl::util::toString(error);
callback.Call(env, method, jni::Make<jni::String>(env, message));
auto jmessage = jni::Make<jni::String>(env, message);
callback.Call(env, method, jmessage);
jni::DeleteLocalRef(env, jmessage);
}

void OfflineManager::ListOfflineRegionsCallback::onList(jni::JNIEnv& env,
Expand Down Expand Up @@ -138,7 +140,9 @@ void OfflineManager::CreateOfflineRegionCallback::onError(jni::JNIEnv& env,
std::exception_ptr error) {
static auto method = javaClass.GetMethod<void (jni::String)>(env, "onError");
std::string message = mbgl::util::toString(error);
callback.Call(env, method, jni::Make<jni::String>(env, message));
auto jmessage = jni::Make<jni::String>(env, message);
callback.Call(env, method, jmessage);
jni::DeleteLocalRef(env, jmessage);
}

void OfflineManager::CreateOfflineRegionCallback::onCreate(jni::JNIEnv& env,
Expand Down
12 changes: 9 additions & 3 deletions platform/android/src/offline/offline_region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ void OfflineRegion::OfflineRegionStatusCallback::onError(jni::JNIEnv& env,
std::exception_ptr error) {
static auto method = javaClass.GetMethod<void (jni::String)>(env, "onError");
std::string message = mbgl::util::toString(error);
callback.Call(env, method, jni::Make<jni::String>(env, message));
auto jmessage = jni::Make<jni::String>(env, message);
callback.Call(env, method, jmessage);
jni::DeleteLocalRef(env, jmessage);
}

void OfflineRegion::OfflineRegionStatusCallback::onStatus(jni::JNIEnv& env,
Expand Down Expand Up @@ -267,7 +269,9 @@ void OfflineRegion::OfflineRegionDeleteCallback::onError(jni::JNIEnv& env,
std::exception_ptr error) {
static auto method = javaClass.GetMethod<void (jni::String)>(env, "onError");
std::string message = mbgl::util::toString(error);
callback.Call(env, method, jni::Make<jni::String>(env, message));
auto jmessage = jni::Make<jni::String>(env, message);
callback.Call(env, method, jmessage);
jni::DeleteLocalRef(env, jmessage);
}

void OfflineRegion::OfflineRegionDeleteCallback::onDelete(jni::JNIEnv& env, jni::Object<OfflineRegion::OfflineRegionDeleteCallback> callback) {
Expand All @@ -289,7 +293,9 @@ void OfflineRegion::OfflineRegionUpdateMetadataCallback::onError(jni::JNIEnv& en
std::exception_ptr error) {
static auto method = javaClass.GetMethod<void (jni::String)>(env, "onError");
std::string message = mbgl::util::toString(error);
callback.Call(env, method, jni::Make<jni::String>(env, message));
auto jmessage = jni::Make<jni::String>(env, message);
callback.Call(env, method, jmessage);
jni::DeleteLocalRef(env, jmessage);
}

void OfflineRegion::OfflineRegionUpdateMetadataCallback::onUpdate(jni::JNIEnv& env,
Expand Down
4 changes: 3 additions & 1 deletion platform/android/src/snapshotter/map_snapshotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ void MapSnapshotter::start(JNIEnv& env) {
if (err) {
// error handler callback
static auto onSnapshotFailed = javaClass.GetMethod<void (jni::String)>(*_env, "onSnapshotFailed");
javaPeer->Call(*_env, onSnapshotFailed, jni::Make<jni::String>(*_env, util::toString(err)));
auto message = jni::Make<jni::String>(*_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);
Expand Down

0 comments on commit c1dabbd

Please sign in to comment.