summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkevin <kevin.li@mapbox.com>2020-07-16 11:36:01 +0800
committerkevin <kevin.li@mapbox.com>2020-07-16 11:36:01 +0800
commit1159d99089b7ea6d45cca3aa469a98922f8c096a (patch)
tree8dc6a3ab46ea3a5aca2fa4c5fda059c9f2d1dc79
parent839deb0105c3eaba71e45ac98e94a921524ddf71 (diff)
downloadqtlocation-mapboxgl-1159d99089b7ea6d45cca3aa469a98922f8c096a.tar.gz
Fix remove source memory leak.
Cherry-pick from https://github.com/mapbox/mapbox-gl-native-android/pull/412
-rw-r--r--platform/android/src/style/sources/custom_geometry_source.cpp8
-rw-r--r--platform/android/src/style/sources/source.cpp6
2 files changed, 9 insertions, 5 deletions
diff --git a/platform/android/src/style/sources/custom_geometry_source.cpp b/platform/android/src/style/sources/custom_geometry_source.cpp
index dccca4cf46..5def7b7ea9 100644
--- a/platform/android/src/style/sources/custom_geometry_source.cpp
+++ b/platform/android/src/style/sources/custom_geometry_source.cpp
@@ -111,10 +111,10 @@ namespace android {
static auto& javaClass = jni::Class<CustomGeometrySource>::Singleton(*_env);
static auto releaseThreads = javaClass.GetMethod<void ()>(*_env, "releaseThreads");
- assert(javaPeer);
-
- auto peer = jni::Cast(*_env, javaClass, javaPeer);
- peer.Call(*_env, releaseThreads);
+ if(javaPeer) {
+ auto peer = jni::Cast(*_env, javaClass, javaPeer);
+ peer.Call(*_env, releaseThreads);
+ }
};
bool CustomGeometrySource::isCancelled(jni::jint z,
diff --git a/platform/android/src/style/sources/source.cpp b/platform/android/src/style/sources/source.cpp
index 786e5cb586..485f4284e4 100644
--- a/platform/android/src/style/sources/source.cpp
+++ b/platform/android/src/style/sources/source.cpp
@@ -67,6 +67,10 @@ namespace android {
}
Source::~Source() {
+ if (ownedSource) {
+ ownedSource.reset();
+ ownedSource.release();
+ }
// Before being added to a map, the Java peer owns this C++ peer and cleans
// up after itself correctly through the jni native peer bindings.
// After being added to the map, the ownership is flipped and the C++ peer has a strong reference
@@ -137,7 +141,7 @@ namespace android {
// Release the strong reference to the java peer
assert(javaPeer);
- javaPeer.release();
+ javaPeer.reset();
rendererFrontend = nullptr;
}