diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-03-25 09:39:49 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-03-25 09:39:49 (GMT) |
commit | e34a24dcd49c055741c9a5914479842021175551 (patch) | |
tree | 5fb0f590c47967805b426da14c6d872bde3480a1 /src/corelib/tools | |
parent | c3776865dd3731917adf9a8ec8cdffb79a579bae (diff) | |
download | Qt-e34a24dcd49c055741c9a5914479842021175551.zip Qt-e34a24dcd49c055741c9a5914479842021175551.tar.gz Qt-e34a24dcd49c055741c9a5914479842021175551.tar.bz2 |
Fix QSharedPointer crashing when it is used as a global static in an application.
If it's used as a static, then the order of destruction is
ill-defined. The QSharedPointer object may be destroyed after our
Q_GLOBAL_STATIC knownPointers has been deleted, thus causing a
null-pointer dereference.
Reviewed-by: Peter Hartmann <peter.hartmann@nokia.com>
Task-number: 246843
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qsharedpointer.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index d8a9923..c3a989e 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -842,15 +842,19 @@ QT_BEGIN_NAMESPACE */ void QtSharedPointer::internalSafetyCheckAdd(const volatile void *ptr) { - QMutexLocker lock(&knownPointers()->mutex); + KnownPointers *const kp = knownPointers(); + if (!kp) + return; // end-game: the application is being destroyed already + + QMutexLocker lock(&kp->mutex); void *actual = const_cast<void*>(ptr); - if (knownPointers()->values.contains(actual)) { + if (kp->values.contains(actual)) { printBacktrace(knownPointers()->values.value(actual)); qFatal("QSharedPointerData: internal self-check failed: pointer %p was already tracked " "by another QSharedPointerData object", actual); } - knownPointers()->values.insert(actual, saveBacktrace()); + kp->values.insert(actual, saveBacktrace()); } /*! @@ -858,9 +862,13 @@ void QtSharedPointer::internalSafetyCheckAdd(const volatile void *ptr) */ void QtSharedPointer::internalSafetyCheckRemove(const volatile void *ptr) { - QMutexLocker lock(&knownPointers()->mutex); + KnownPointers *const kp = knownPointers(); + if (!kp) + return; // end-game: the application is being destroyed already + + QMutexLocker lock(&kp->mutex); void *actual = const_cast<void*>(ptr); - knownPointers()->values.remove(actual); + kp->values.remove(actual); } QT_END_NAMESPACE |