From 744ff7738333c35e7d621c61d72422cf3a8e7fe4 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 1 Sep 2010 15:24:25 +1000 Subject: Destroy QNetworkConfigurationManager global static from qApp dtor. The order of global static destruction is not well defined. Ensure that the QNetworkConfigurationManager global static is destroyed from the QCoreApplication destructor before its dependencies are destroyed with the rest of the global statics. Task-number: QTBUG-13304 --- src/network/bearer/qnetworkconfigmanager.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 65014a6..23d7800 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -45,12 +45,33 @@ #include "qbearerengine_p.h" #include +#include #ifndef QT_NO_BEARERMANAGEMENT QT_BEGIN_NAMESPACE -Q_GLOBAL_STATIC(QNetworkConfigurationManagerPrivate, connManager); +#define Q_GLOBAL_STATIC_QAPP_DESTRUCTION(TYPE, NAME) \ + Q_GLOBAL_STATIC_INIT(TYPE, NAME); \ + static void NAME##_cleanup() \ + { \ + delete this_##NAME.pointer; \ + this_##NAME.pointer = 0; \ + this_##NAME.destroyed = true; \ + } \ + static TYPE *NAME() \ + { \ + if (!this_##NAME.pointer && !this_##NAME.destroyed) { \ + TYPE *x = new TYPE; \ + if (!this_##NAME.pointer.testAndSetOrdered(0, x)) \ + delete x; \ + else \ + qAddPostRoutine(NAME##_cleanup); \ + } \ + return this_##NAME.pointer; \ + } + +Q_GLOBAL_STATIC_QAPP_DESTRUCTION(QNetworkConfigurationManagerPrivate, connManager); QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate() { -- cgit v0.12