summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2014-09-20 18:52:15 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2014-09-22 18:56:50 +0200
commit8c2f0ac3827e765dfd31711ad576b396df7df467 (patch)
tree41d83582251181149f8e9df64d03c0003979e3e3 /src/corelib/kernel
parentd9e1a0f05b30fd646a6b473bea605f6054bf0e67 (diff)
QObject: fix a memory leak in moveToThread
For some reason it seems to be supported to call moveToThread(0). That call will allocate a new QThreadData for the object. However, if we then detect that we're calling moveToThread from a thread which is not the one the QObject has affinity with, we error out leaking that QThreadData object. Change-Id: I0fe6625a2a9887535e457f3897b514d2a03d1480 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qobject.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index e588808ee8..9ab952362c 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -1461,14 +1461,14 @@ void QObject::moveToThread(QThread *targetThread)
}
QThreadData *currentData = QThreadData::current();
- QThreadData *targetData = targetThread ? QThreadData::get2(targetThread) : new QThreadData(0);
+ QThreadData *targetData = targetThread ? QThreadData::get2(targetThread) : Q_NULLPTR;
if (d->threadData->thread == 0 && currentData == targetData) {
// one exception to the rule: we allow moving objects with no thread affinity to the current thread
currentData = d->threadData;
} else if (d->threadData != currentData) {
qWarning("QObject::moveToThread: Current thread (%p) is not the object's thread (%p).\n"
"Cannot move to target thread (%p)\n",
- currentData->thread, d->threadData->thread, targetData->thread);
+ currentData->thread, d->threadData->thread, targetData ? targetData->thread : Q_NULLPTR);
#ifdef Q_OS_MAC
qWarning("On Mac OS X, you might be loading two sets of Qt binaries into the same process. "
@@ -1482,6 +1482,9 @@ void QObject::moveToThread(QThread *targetThread)
// prepare to move
d->moveToThread_helper();
+ if (!targetData)
+ targetData = new QThreadData(0);
+
QOrderedMutexLocker locker(&currentData->postEventList.mutex,
&targetData->postEventList.mutex);