Fix data race in accessing QDBusConnectionPrivate::serviceNames

The trick of creating a copy is not thread-safe. I'd known this since
the moment I wrote that code, but thought "what could go wrong?".

Task-number: QTBUG-39285
Change-Id: If521d4a649c06e6a34926687e85623aa25cb4c35
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Thiago Macieira 2014-06-08 14:49:36 -04:00
parent 66bd87e5c6
commit acd0dae3f4
2 changed files with 7 additions and 4 deletions

View File

@ -256,7 +256,7 @@ private:
void deliverCall(QObject *object, int flags, const QDBusMessage &msg,
const QVector<int> &metaTypes, int slotIdx);
bool isServiceRegisteredByThread(const QString &serviceName) const;
bool isServiceRegisteredByThread(const QString &serviceName);
QString getNameOwnerNoCache(const QString &service);

View File

@ -2488,12 +2488,15 @@ void QDBusConnectionPrivate::unregisterServiceNoLock(const QString &serviceName)
serviceNames.removeAll(serviceName);
}
bool QDBusConnectionPrivate::isServiceRegisteredByThread(const QString &serviceName) const
bool QDBusConnectionPrivate::isServiceRegisteredByThread(const QString &serviceName)
{
if (!serviceName.isEmpty() && serviceName == baseService)
return true;
QStringList copy = serviceNames;
return copy.contains(serviceName);
if (serviceName == dbusServiceString())
return false;
QDBusReadLocker locker(UnregisterServiceAction, this);
return serviceNames.contains(serviceName);
}
void QDBusConnectionPrivate::postEventToThread(int action, QObject *object, QEvent *ev)