From 7cdc39bee90dbf7658cb280b4fba9e63de18bc31 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Fri, 8 Mar 2019 19:14:38 +0200 Subject: [PATCH] [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. --- platform/qt/src/qmapboxgl.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index 49b0dc021..a3ec1bf0e 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -103,7 +103,7 @@ std::shared_ptr 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 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.