From eacff46af4216d0482c304aaf3d0d2e69368feeb Mon Sep 17 00:00:00 2001 From: Ievgenii Meshcheriakov Date: Fri, 8 Sep 2023 16:26:23 +0200 Subject: [PATCH] QtDBus: Check if QDBusServer is destroyed before accessing it Also lock before accessing serverObject member, it is cleared by ~QDBusServer(). Task-number: QTBUG-116621 Change-Id: I14c96e34316a46fe43ecd929e44cd1800ba8b803 Reviewed-by: Thiago Macieira --- src/dbus/qdbusintegrator.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 276a3fcc3f..e0478d0d48 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -313,6 +313,10 @@ static void qDBusNewConnection(DBusServer *server, DBusConnection *connection, v newConnection->setPeer(connection, error); newConnection->setDispatchEnabled(false); + QReadLocker serverLock(&serverConnection->lock); + if (!serverConnection->serverObject) + return; + // this is a queued connection and will resume in the QDBusServer's thread QMetaObject::invokeMethod(serverConnection->serverObject, &QDBusServer::newConnection, Qt::QueuedConnection, QDBusConnectionPrivate::q(newConnection)); @@ -321,7 +325,7 @@ static void qDBusNewConnection(DBusServer *server, DBusConnection *connection, v // QDBusServer's thread in order to enable it after the // QDBusServer::newConnection() signal has been received by the // application's code - QReadLocker serverLock(&serverConnection->lock); + newConnection->enableDispatchDelayed(serverConnection->serverObject); }