From f273d6fbc02055ff3999adc0df76360ca0670435 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Tue, 9 Apr 2013 18:25:00 +0200 Subject: QNetworkConfigurationManager: check whether app is shutting down ... before trying to update the configurations. Before, we would check whether the pointer to the QNetworkConfigurationManagerPrivate instance was 0 and in that case construct it. This would mean that this code path was taken "at app shutdown", i.e. when the qAddPostRoutine had already been called but the other statics were still accessed. Note: This is not thread safe, but neither is the rest of the code; making it thread-safe would require additional changes. Task-number: QTBUG-30585 Change-Id: I8f6cf616e3f3ba1e84b8246589fb7210d2dae57a Reviewed-by: Frederik Gladhorn Reviewed-by: Stephen Kelly --- src/network/bearer/qnetworkconfigmanager.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 49d6babb10..4f74936ac7 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -55,10 +55,13 @@ QT_BEGIN_NAMESPACE static QBasicAtomicPointer connManager_ptr; +static QBasicAtomicInt appShutdown; static void connManager_cleanup() { // this is not atomic or thread-safe! + int shutdown = appShutdown.fetchAndStoreAcquire(1); + Q_ASSERT(shutdown == 0); QNetworkConfigurationManagerPrivate *cmp = connManager_ptr.fetchAndStoreAcquire(0); if (cmp) cmp->cleanup(); @@ -72,7 +75,8 @@ void QNetworkConfigurationManagerPrivate::addPostRoutine() QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate() { QNetworkConfigurationManagerPrivate *ptr = connManager_ptr.loadAcquire(); - if (!ptr) { + int shutdown = appShutdown.loadAcquire(); + if (!ptr && !shutdown) { static QBasicMutex connManager_mutex; QMutexLocker locker(&connManager_mutex); if (!(ptr = connManager_ptr.loadAcquire())) { -- cgit v1.2.3