From c8631d23f5afad73044071695775691c7e794d07 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sat, 11 May 2019 22:34:49 +0000 Subject: [PATCH] dbus fixes this includes the following upstream commits: https://github.com/qt/qtbase/commit/e4eb9bfbf74385cb3ee5d7225814be697aa47285 https://github.com/qt/qtbase/commit/2bcbe227bdcfded9ae01b289e78aa9e117613056 https://github.com/qt/qtbase/commit/fb166648936410f791ae6e600756d255b4a50545 https://github.com/qt/qtbase/commit/d370878aa0510e1e51eb9014965f505e395f3f81 Signed-off-by: Ivailo Monev --- src/dbus/qdbusintegrator.cpp | 22 ++++++++++++++++++---- src/dbus/qdbusserver.cpp | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index bd598f070..46b84ab78 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -69,6 +69,9 @@ QT_BEGIN_NAMESPACE +// used with dbus_server_allocate_data_slot +static dbus_int32_t server_slot = -1; + static QAtomicInt isDebugging = QAtomicInt(-1); #define qDBusDebug if (isDebugging == 0); else qDebug @@ -557,7 +560,7 @@ qDBusSignalFilter(DBusConnection *connection, DBusMessage *message, void *data) bool QDBusConnectionPrivate::handleMessage(const QDBusMessage &amsg) { const QDBusSpyHookList *list = qDBusSpyHookList(); - for (int i = 0; i < list->size(); ++i) { + for (int i = 0; list && i < list->size(); ++i) { qDBusDebug() << "calling the message spy hook"; (*(*list)[i])(amsg); } @@ -1004,6 +1007,15 @@ QDBusConnectionPrivate::~QDBusConnectionPrivate() "Timer and socket errors will follow and the program will probably crash", qPrintable(name)); + if (mode == ClientMode) { + // the bus service object holds a reference back to us; + // we need to destroy it before we finish destroying ourself + Q_ASSERT(ref.load() == 0); + QObject *obj = (QObject*)busService; + disconnect(obj, Q_NULLPTR, this, Q_NULLPTR); + delete obj; + } + closeConnection(); rootNode.children.clear(); // free resources qDeleteAll(cachedMetaObjects); @@ -1024,8 +1036,10 @@ void QDBusConnectionPrivate::closeConnection() mode = InvalidMode; // prevent reentrancy baseService.clear(); - if (server) + if (server) { dbus_server_disconnect(server); + dbus_server_free_data_slot(&server_slot); + } if (oldMode == ClientMode || oldMode == PeerMode) { if (connection) { @@ -1120,6 +1134,7 @@ void QDBusConnectionPrivate::socketRead(int fd) if (it->watch && it->read && it->read->isEnabled()) { if (!dbus_watch_handle(it.value().watch, DBUS_WATCH_READABLE)) qDebug("OUT OF MEM"); + break; } ++it; } @@ -1135,6 +1150,7 @@ void QDBusConnectionPrivate::socketWrite(int fd) if (it->watch && it->write && it->write->isEnabled()) { if (!dbus_watch_handle(it.value().watch, DBUS_WATCH_WRITABLE)) qDebug("OUT OF MEM"); + break; } ++it; } @@ -1586,8 +1602,6 @@ void QDBusConnectionPrivate::handleSignal(const QDBusMessage& msg) handleSignal(key, msg); // third try } -static dbus_int32_t server_slot = -1; - void QDBusConnectionPrivate::setServer(DBusServer *s, const QDBusErrorInternal &error) { if (!s) { diff --git a/src/dbus/qdbusserver.cpp b/src/dbus/qdbusserver.cpp index eb187cc59..e55e64c41 100644 --- a/src/dbus/qdbusserver.cpp +++ b/src/dbus/qdbusserver.cpp @@ -85,6 +85,8 @@ QDBusServer::~QDBusServer() QDBusConnectionManager::instance()->removeConnection(name); } d->serverConnectionNames.clear(); + d->ref = 0; + d->deleteLater(); } }