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 <frederik.gladhorn@digia.com>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Peter Hartmann 2013-04-09 18:25:00 +02:00 committed by The Qt Project
parent 0eefbf8376
commit f273d6fbc0

View File

@ -55,10 +55,13 @@
QT_BEGIN_NAMESPACE
static QBasicAtomicPointer<QNetworkConfigurationManagerPrivate> 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())) {