diff options
author | André Klitzing <aklitzing@gmail.com> | 2020-05-19 13:00:57 +0200 |
---|---|---|
committer | André Klitzing <aklitzing@gmail.com> | 2020-06-23 14:01:11 +0200 |
commit | 7e5a803c08c38e4fddc4338848768b7cfff4848f (patch) | |
tree | dffc3c1c61b26f82cbd2965e56e4b79b3663a018 | |
parent | 0fb1774a0aa1b741b0d491b6ac9e63c1b5f8631e (diff) |
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.
Pick-to: 5.15
Task-number: QTBUG-84234
Change-Id: I96be4601c3af38fa7c753a6f7acb8273ee277a27
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
-rw-r--r-- | src/network/kernel/qhostinfo.cpp | 21 |
1 files 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<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; +} + } /* |