Don't crash if the relayed signal was emitted from the wrong thread

Under normal circumstances, this should never happen. Signals exported
to D-Bus should only be emitted from the object's own thread. That's the
only way for the receiver (the QDBusAdaptorConnector object) to know
what the sender object and signal were. If they are emitted from another
thread, the sender will be null.

Task-number: QTBUG-31932
Change-Id: Ia5a45d648985e0645bffd4abc0881fca9da64f79
Reviewed-by: Lorn Potter <lorn.potter@jollamobile.com>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
bb10
Thiago Macieira 2013-06-23 16:52:13 -07:00 committed by The Qt Project
parent efb592503a
commit d94961d08f
1 changed files with 10 additions and 1 deletions

View File

@ -279,7 +279,16 @@ void QDBusAdaptorConnector::polish()
void QDBusAdaptorConnector::relaySlot(void **argv)
{
relay(sender(), senderSignalIndex(), argv);
QObject *sndr = sender();
if (Q_LIKELY(sndr)) {
relay(sndr, senderSignalIndex(), argv);
} else {
qWarning("QtDBus: cannot relay signals from parent %s(%p \"%s\") unless they are emitted in the object's thread %s(%p \"%s\"). "
"Current thread is %s(%p \"%s\").",
parent()->metaObject()->className(), parent(), qPrintable(parent()->objectName()),
parent()->thread()->metaObject()->className(), parent()->thread(), qPrintable(parent()->thread()->objectName()),
QThread::currentThread()->metaObject()->className(), QThread::currentThread(), qPrintable(QThread::currentThread()->objectName()));
}
}
void QDBusAdaptorConnector::relay(QObject *senderObj, int lastSignalIdx, void **argv)