KDirectoryContentsCounter: do not delete currently active worker objects

Before this patch, the destructor of KDirectoryContentsCounter might
delete the worker object, which lives in another thread, while one of
its methods was still being executed. This could cause a crash. Only if
the destroyed KDirectoryContentsCounter was the last one, the worker
thread was stopped, and the destructor waited until all workers are
done.

BUG: 332767
FIXED-IN: 4.13.0
REVIEW: 117209
This commit is contained in:
Frank Reininghaus 2014-04-03 09:03:47 +02:00
parent 05acaf9345
commit 0d191c9da2

View file

@ -60,14 +60,23 @@ KDirectoryContentsCounter::~KDirectoryContentsCounter()
{
--m_workersCount;
if (m_workersCount == 0) {
if (m_workersCount > 0) {
// The worker thread will continue running. It could even be running
// a method of m_worker at the moment, so we delete it using
// deleteLater() to prevent a crash.
m_worker->deleteLater();
} else {
// There are no remaining workers -> stop the worker thread.
m_workerThread->quit();
m_workerThread->wait();
delete m_workerThread;
m_workerThread = 0;
}
delete m_worker;
// The worker thread has finished running now, so it's safe to delete
// m_worker. deleteLater() would not work at all because the event loop
// which would deliver the event to m_worker is not running any more.
delete m_worker;
}
}
void KDirectoryContentsCounter::addDirectory(const QString& path)