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>
This commit is contained in:
André Klitzing 2020-05-19 13:00:57 +02:00
parent 0fb1774a0a
commit 7e5a803c08

View File

@ -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;
}
}
/*