From 82edcd4e12d2652d63ec0732d8053b2761562d3d Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Fri, 20 Dec 2013 19:34:06 +0100 Subject: Don't leak pending call objects when peer disconnects Unlike in regular connection to DBus server, we don't get pending call notifies when a peer drops the connection in peer-to-peer mode. Thus, we need to keep track of pending calls in such cases and get rid of them in ~QDBusConnectionPrivate(). Change-Id: I83e20db0bc7b2ebf509c7fdb1382ffc7d0ede9d3 Done-with: Kalle Vahlman Reviewed-by: Daniele E. Domenichelli Reviewed-by: Thiago Macieira --- src/dbus/qdbusconnection_p.h | 2 ++ src/dbus/qdbusintegrator.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) (limited to 'src') diff --git a/src/dbus/qdbusconnection_p.h b/src/dbus/qdbusconnection_p.h index 515eab6dfe..350e49a50d 100644 --- a/src/dbus/qdbusconnection_p.h +++ b/src/dbus/qdbusconnection_p.h @@ -178,6 +178,7 @@ public: typedef QMultiHash SignalHookHash; typedef QHash MetaObjectHash; typedef QHash MatchRefCountHash; + typedef QList PendingCallList; struct WatchedServiceData { WatchedServiceData() : refcount(0) {} @@ -316,6 +317,7 @@ public: MatchRefCountHash matchRefCounts; ObjectTreeNode rootNode; MetaObjectHash cachedMetaObjects; + PendingCallList pendingCalls; QMutex callDeliveryMutex; QDBusCallDeliveryEvent *callDeliveryState; // protected by the callDeliveryMutex mutex diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index d797fbfb99..77de09d197 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -1092,6 +1092,9 @@ void QDBusConnectionPrivate::closeConnection() ; } } + + qDeleteAll(pendingCalls); + qDBusDebug() << this << "Disconnected"; } @@ -1834,6 +1837,8 @@ void QDBusConnectionPrivate::processFinishedCall(QDBusPendingCallPrivate *call) QMutexLocker locker(&call->mutex); + connection->pendingCalls.removeOne(call); + QDBusMessage &msg = call->replyMessage; if (call->pending) { // decode the message @@ -2094,6 +2099,10 @@ QDBusPendingCallPrivate *QDBusConnectionPrivate::sendWithReplyAsync(const QDBusM pcall->pending = pending; q_dbus_pending_call_set_notify(pending, qDBusResultReceived, pcall, 0); + // DBus won't notify us when a peer disconnects so we need to track these ourselves + if (mode == QDBusConnectionPrivate::PeerMode) + pendingCalls.append(pcall); + return pcall; } else { // we're probably disconnected at this point -- cgit v1.2.3