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 <kalle.vahlman@movial.com>
Reviewed-by: Daniele E. Domenichelli <daniele.domenichelli@gmail.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Robin Burchell 2013-12-20 19:34:06 +01:00 committed by The Qt Project
parent 56d141ae6b
commit 82edcd4e12
2 changed files with 11 additions and 0 deletions

View File

@ -178,6 +178,7 @@ public:
typedef QMultiHash<QString, SignalHook> SignalHookHash;
typedef QHash<QString, QDBusMetaObject* > MetaObjectHash;
typedef QHash<QByteArray, int> MatchRefCountHash;
typedef QList<QDBusPendingCallPrivate*> 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

View File

@ -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