From 7e5a803c08c38e4fddc4338848768b7cfff4848f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Klitzing?= Date: Tue, 19 May 2020 13:00:57 +0200 Subject: [PATCH] Fix living QObject member after shutdown of QCoreApplication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Pick-to: 5.15 Task-number: QTBUG-84234 Change-Id: I96be4601c3af38fa7c753a6f7acb8273ee277a27 Reviewed-by: MÃ¥rten Nordheim --- src/network/kernel/qhostinfo.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index 115f3445b9..db414a52f2 100644 --- a/src/network/kernel/qhostinfo.cpp +++ b/src/network/kernel/qhostinfo.cpp @@ -71,8 +71,6 @@ QT_BEGIN_NAMESPACE //#define QHOSTINFO_DEBUG -Q_GLOBAL_STATIC(QHostInfoLookupManager, theHostInfoLookupManager) - namespace { struct ToBeLookedUpEquals { typedef bool result_type; @@ -101,6 +99,25 @@ std::pair 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; +} + } /*