Fix living QObject after shutdown of QCoreApplication

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: Ia82bcff2b564b753ed687f025ff86fa1bed1e64c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
André Klitzing 2020-05-19 12:50:35 +02:00
parent 727fab7d29
commit 1304040e5d
2 changed files with 11 additions and 4 deletions

View File

@ -892,8 +892,10 @@ QCoreApplication::~QCoreApplication()
} QT_CATCH (...) {
// swallow the exception, since destructors shouldn't throw
}
if (globalThreadPool)
if (globalThreadPool) {
globalThreadPool->waitForDone();
delete globalThreadPool;
}
#endif
#ifndef QT_NO_QOBJECT

View File

@ -40,13 +40,12 @@
#include "qthreadpool.h"
#include "qthreadpool_p.h"
#include "qdeadlinetimer.h"
#include "qcoreapplication.h"
#include <algorithm>
QT_BEGIN_NAMESPACE
Q_GLOBAL_STATIC(QThreadPool, theInstance)
/*
QThread wrapper, provides synchronization against a ThreadPool
*/
@ -478,7 +477,13 @@ QThreadPool::~QThreadPool()
*/
QThreadPool *QThreadPool::globalInstance()
{
return theInstance();
static QPointer<QThreadPool> theInstance;
static QBasicMutex theMutex;
const QMutexLocker locker(&theMutex);
if (theInstance.isNull() && !QCoreApplication::closingDown())
theInstance = new QThreadPool();
return theInstance;
}
/*!