summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2019-03-08 19:14:38 +0200
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2019-03-08 20:56:45 +0200
commit7cdc39bee90dbf7658cb280b4fba9e63de18bc31 (patch)
treeffc5c23dca49b0869083f44b22e6d73913a761cf /platform
parent5e2b6bf636472a4464e6ab3ae0d9d01c68de041b (diff)
downloadqtlocation-mapboxgl-7cdc39bee90dbf7658cb280b4fba9e63de18bc31.tar.gz
[Qt] Fix race when locking a FileSource
We were returning the FileSource, it could have expired already. We _need_ to check if the lock() on the weak pointer worked before returning.
Diffstat (limited to 'platform')
-rw-r--r--platform/qt/src/qmapboxgl.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index 49b0dc021c..a3ec1bf0e4 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -103,7 +103,7 @@ std::shared_ptr<mbgl::DefaultFileSource> sharedDefaultFileSource(const QMapboxGL
// Purge entries no longer in use.
for (auto it = fileSources.begin(); it != fileSources.end();) {
- if (!it->second.lock()) {
+ if (it->second.expired()) {
it = fileSources.erase(it);
} else {
++it;
@@ -115,7 +115,10 @@ std::shared_ptr<mbgl::DefaultFileSource> sharedDefaultFileSource(const QMapboxGL
// Return an existing FileSource if available.
auto sharedFileSource = fileSources.find(key);
if (sharedFileSource != fileSources.end()) {
- return sharedFileSource->second.lock();
+ auto lockedSharedFileSource = sharedFileSource->second.lock();
+ if (lockedSharedFileSource) {
+ return lockedSharedFileSource;
+ }
}
// New path, create a new FileSource.