summaryrefslogtreecommitdiff
path: root/src/network/kernel/qhostinfo.cpp
diff options
context:
space:
mode:
authorAndré Klitzing <aklitzing@gmail.com>2020-05-19 13:00:57 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-06-29 14:13:38 +0000
commitabad47724c515d59977951c6bc05a155a9ed58f2 (patch)
tree2b7bc0511fe3faf18139e09936c68383a00aa5a0 /src/network/kernel/qhostinfo.cpp
parent78665d8a0cc06aa17a0dc3987afb6d2f3d86e6af (diff)
downloadqtbase-abad47724c515d59977951c6bc05a155a9ed58f2.tar.gz
Fix living QObject member after shutdown of QCoreApplication
QHostInfoLookupManager has a QThreadPool as member. QThreadPool is a QObject and must be deleted if the QCoreApplication is being destroyed to release the underlying ThreadData. A Q_GLOBAL_STATIC won't release any memory is not able to manually release it. Task-number: QTBUG-84234 Change-Id: I96be4601c3af38fa7c753a6f7acb8273ee277a27 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 7e5a803c08c38e4fddc4338848768b7cfff4848f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/network/kernel/qhostinfo.cpp')
-rw-r--r--src/network/kernel/qhostinfo.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp
index 93be053ef3..33fb629899 100644
--- a/src/network/kernel/qhostinfo.cpp
+++ b/src/network/kernel/qhostinfo.cpp
@@ -72,8 +72,6 @@ QT_BEGIN_NAMESPACE
//#define QHOSTINFO_DEBUG
-Q_GLOBAL_STATIC(QHostInfoLookupManager, theHostInfoLookupManager)
-
namespace {
struct ToBeLookedUpEquals {
typedef bool result_type;
@@ -102,6 +100,25 @@ std::pair<OutputIt1, OutputIt2> separate_if(InputIt first, InputIt last, OutputI
return std::make_pair(dest1, dest2);
}
+QHostInfoLookupManager* theHostInfoLookupManager()
+{
+ static QHostInfoLookupManager* theManager = nullptr;
+ static QBasicMutex theMutex;
+
+ const QMutexLocker locker(&theMutex);
+ if (theManager == nullptr) {
+ theManager = new QHostInfoLookupManager();
+ Q_ASSERT(QCoreApplication::instance());
+ QObject::connect(QCoreApplication::instance(), &QCoreApplication::destroyed, [] {
+ const QMutexLocker locker(&theMutex);
+ delete theManager;
+ theManager = nullptr;
+ });
+ }
+
+ return theManager;
+}
+
}
/*