summaryrefslogtreecommitdiff
path: root/platform/qt
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2017-07-13 16:38:42 +0300
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2017-07-14 15:18:54 +0300
commit48ddfef89ff4daa2e26d3338dbfc20c4f4cc7d21 (patch)
treedfe3e3518719411f97dc441fb14f4ddfc5af47fd /platform/qt
parent3b26177e9d3d9ed87f96ac33e7ed74bc7653f661 (diff)
downloadqtlocation-mapboxgl-48ddfef89ff4daa2e26d3338dbfc20c4f4cc7d21.tar.gz
[core] Make sure ThreadLocal will not own the pointer it is managing
ThreadLocal should not own the pointer it is managing because the use case in Mapbox GL is to keep a pointer to a stack allocated object, like: ``` MyObject foo; threadLocal.set(&foo); ``` To keep consistency, it is required that we clear the managed object before ThreadLocal gets destroyed by setting it to `nullptr`.
Diffstat (limited to 'platform/qt')
-rw-r--r--platform/qt/src/thread_local.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/platform/qt/src/thread_local.cpp b/platform/qt/src/thread_local.cpp
index e48a9d6e74..e835a680e2 100644
--- a/platform/qt/src/thread_local.cpp
+++ b/platform/qt/src/thread_local.cpp
@@ -4,6 +4,7 @@
#include <mbgl/map/backend_scope.hpp>
#include <array>
+#include <cassert>
#include <QThreadStorage>
@@ -23,7 +24,11 @@ ThreadLocal<T>::ThreadLocal() : impl(std::make_unique<Impl>()) {
template <class T>
ThreadLocal<T>::~ThreadLocal() {
- delete get();
+ // ThreadLocal will not take ownership
+ // of the pointer it is managing. The pointer
+ // needs to be explicitly cleared before we
+ // destroy this object.
+ assert(!get());
}
template <class T>