diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2015-07-19 22:04:28 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2015-08-26 23:13:47 +0900 |
commit | 8eefba828fef6908ef67d610e9fbbb4abb28d3ba (patch) | |
tree | c8887269085094c5f9ae56dec797da1001f06003 /src | |
parent | d1fd5b9b238e16c1ee25f9dbb00a6a964d4061b9 (diff) | |
download | qt3-8eefba828fef6908ef67d610e9fbbb4abb28d3ba.tar.gz qt3-8eefba828fef6908ef67d610e9fbbb4abb28d3ba.zip |
Added safety harness for currentThreadObject() usage.
currentThreadObject() returns a null pointer if the
current thread was not started using the QThread API.
This relates to bug 1748.
(cherry picked from commit dad70b4c5201ece044ecb663bb91b48ba8bd84a3)
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/qeventloop_unix_glib.cpp | 8 | ||||
-rw-r--r-- | src/kernel/qobject.cpp | 24 |
2 files changed, 25 insertions, 7 deletions
diff --git a/src/kernel/qeventloop_unix_glib.cpp b/src/kernel/qeventloop_unix_glib.cpp index feff675..c41acce 100644 --- a/src/kernel/qeventloop_unix_glib.cpp +++ b/src/kernel/qeventloop_unix_glib.cpp @@ -688,7 +688,9 @@ int QEventLoop::activateTimers() QTimerEvent e( t->id ); #if defined(QT_THREAD_SUPPORT) // Be careful...the current thread may not be the target object's thread! - if ((!t->obj) || (QThread::currentThreadObject()->threadPostedEventsDisabled()) || (t->obj && (t->obj->contextThreadObject() == QThread::currentThreadObject()))) { + if ((!t->obj) || + (QThread::currentThreadObject() && QThread::currentThreadObject()->threadPostedEventsDisabled()) || + (t->obj && t->obj->contextThreadObject() == QThread::currentThreadObject())) { QApplication::sendEvent( t->obj, &e ); // send event } else { @@ -731,7 +733,9 @@ int QEventLoop::activateSocketNotifiers() sn->pending = FALSE; #if defined(QT_THREAD_SUPPORT) // Be careful...the current thread may not be the target object's thread! - if ((!sn->obj) || (QThread::currentThreadObject()->threadPostedEventsDisabled()) || (sn->obj && (sn->obj->contextThreadObject() == QThread::currentThreadObject()))) { + if ((!sn->obj) || + (QThread::currentThreadObject() && QThread::currentThreadObject()->threadPostedEventsDisabled()) || + (sn->obj && sn->obj->contextThreadObject() == QThread::currentThreadObject())) { QApplication::sendEvent( sn->obj, &event ); // send event } else { diff --git a/src/kernel/qobject.cpp b/src/kernel/qobject.cpp index d6be971..b48531e 100644 --- a/src/kernel/qobject.cpp +++ b/src/kernel/qobject.cpp @@ -203,9 +203,10 @@ void QObject::moveToThread(QThread *targetThread) } QThread *objectThread = contextThreadObject(); + // NOTE currentThread could be NULL if the current thread was not started using the QThread API QThread *currentThread = QThread::currentThreadObject(); - if (objectThread != currentThread) { + if (currentThread && objectThread != currentThread) { #if defined(QT_DEBUG) qWarning( "QObject::moveToThread: Current thread is not the object's thread" ); #endif @@ -2760,6 +2761,7 @@ void QObject::activate_signal( QConnectionList *clist, QUObject *o ) } #endif + // NOTE currentThread could be NULL if the current thread was not started using the QThread API const QThread *currentThread = QThread::currentThreadObject(); QObject *object; @@ -2779,7 +2781,10 @@ void QObject::activate_signal( QConnectionList *clist, QUObject *o ) sol->currentSender = this; } if ( c->memberType() == QSIGNAL_CODE ) { - if ((d->disableThreadPostedEvents) || (object->d->disableThreadPostedEvents) || (currentThread->threadPostedEventsDisabled()) || (object->d->ownThread == currentThread)) { + if ((d->disableThreadPostedEvents) || + (object->d->disableThreadPostedEvents) || + (currentThread && currentThread->threadPostedEventsDisabled()) || + (currentThread && object->d->ownThread == currentThread)) { #ifdef QT_THREAD_SUPPORT sol->listMutex->unlock(); #endif // QT_THREAD_SUPPORT @@ -2798,7 +2803,10 @@ void QObject::activate_signal( QConnectionList *clist, QUObject *o ) } } else { - if ((d->disableThreadPostedEvents) || (object->d->disableThreadPostedEvents) || (currentThread->threadPostedEventsDisabled()) || (object->d->ownThread == currentThread)) { + if ((d->disableThreadPostedEvents) || + (object->d->disableThreadPostedEvents) || + (currentThread && currentThread->threadPostedEventsDisabled()) || + (currentThread && object->d->ownThread == currentThread)) { #ifdef QT_THREAD_SUPPORT sol->listMutex->unlock(); #endif // QT_THREAD_SUPPORT @@ -2846,7 +2854,10 @@ void QObject::activate_signal( QConnectionList *clist, QUObject *o ) sol->currentSender = this; } if ( c->memberType() == QSIGNAL_CODE ) { - if ((d->disableThreadPostedEvents) || (object->d->disableThreadPostedEvents) || (currentThread->threadPostedEventsDisabled()) || (object->d->ownThread == currentThread)) { + if ((d->disableThreadPostedEvents) || + (object->d->disableThreadPostedEvents) || + (currentThread && currentThread->threadPostedEventsDisabled()) || + (currentThread && object->d->ownThread == currentThread)) { #ifdef QT_THREAD_SUPPORT sol->listMutex->unlock(); #endif // QT_THREAD_SUPPORT @@ -2865,7 +2876,10 @@ void QObject::activate_signal( QConnectionList *clist, QUObject *o ) } } else { - if ((d->disableThreadPostedEvents) || (object->d->disableThreadPostedEvents) || (currentThread->threadPostedEventsDisabled()) || (object->d->ownThread == currentThread)) { + if ((d->disableThreadPostedEvents) || + (object->d->disableThreadPostedEvents) || + (currentThread && currentThread->threadPostedEventsDisabled()) || + (currentThread && object->d->ownThread == currentThread)) { #ifdef QT_THREAD_SUPPORT sol->listMutex->unlock(); #endif // QT_THREAD_SUPPORT |