From 8888eae0d3da23f233ce49cd3457885998444db4 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 3 Apr 2015 23:09:50 -0700 Subject: [PATCH] Merge two more QDBusConnectionPrivate members into a union QDBusConnectionPrivate can only be a client or a server, not both, so the DBusServer and DBusConnection pointers can be shared, like the QDBusConnectionInterface and QDBusServer pointers in the other anonymous union. Change-Id: I9a75ad8521ae4e5cbbe5ffff13d1baa8ab83c42f Reviewed-by: Albert Astals Cid Reviewed-by: Alex Blasche --- src/dbus/qdbusconnection_p.h | 6 ++++-- src/dbus/qdbusintegrator.cpp | 27 ++++++++++++++------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/dbus/qdbusconnection_p.h b/src/dbus/qdbusconnection_p.h index e12b77837e..49c7564566 100644 --- a/src/dbus/qdbusconnection_p.h +++ b/src/dbus/qdbusconnection_p.h @@ -303,8 +303,10 @@ public: // the dispatch lock protects everything related to the DBusConnection or DBusServer // including the timeouts and watches QMutex dispatchLock; - DBusConnection *connection; - DBusServer *server; + union { + DBusConnection *connection; + DBusServer *server; + }; WatcherHash watchers; TimeoutHash timeouts; PendingTimeoutList timeoutsPendingAdd; diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 6fccccabd3..ec9a88a210 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -949,7 +949,7 @@ extern bool qDBusInitThreads(); QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *p) : QObject(p), ref(1), capabilities(0), mode(InvalidMode), busService(0), - dispatchLock(QMutex::Recursive), connection(0), server(0), + dispatchLock(QMutex::Recursive), connection(0), rootNode(QString(QLatin1Char('/'))), anonymousAuthenticationAllowed(false) { @@ -995,22 +995,23 @@ QDBusConnectionPrivate::~QDBusConnectionPrivate() rootNode.children.clear(); // free resources qDeleteAll(cachedMetaObjects); - if (mode == ClientMode) { + if (mode == ClientMode || mode == PeerMode) { // the bus service object holds a reference back to us; // we need to destroy it before we finish destroying ourselves Q_ASSERT(ref.load() == 0); QObject *obj = (QObject *)busService; - disconnect(obj, Q_NULLPTR, this, Q_NULLPTR); - delete obj; + if (obj) { + disconnect(obj, Q_NULLPTR, this, Q_NULLPTR); + delete obj; + } + if (connection) + q_dbus_connection_unref(connection); + connection = 0; + } else if (mode == ServerMode) { + if (server) + q_dbus_server_unref(server); + server = 0; } - - if (server) - q_dbus_server_unref(server); - if (connection) - q_dbus_connection_unref(connection); - - connection = 0; - server = 0; } void QDBusConnectionPrivate::closeConnection() @@ -1020,7 +1021,7 @@ void QDBusConnectionPrivate::closeConnection() mode = InvalidMode; // prevent reentrancy baseService.clear(); - if (server) { + if (oldMode == ServerMode && server) { q_dbus_server_disconnect(server); q_dbus_server_free_data_slot(&server_slot); }