Skip to content

Commit 3c94288

Browse files
committed
Do not destroy the transaction before it has replied
Destroy might be signaled before the dbus call has replied. In destroy() we emit a `finished` event with code ExitUnknown, but if the transaction returns an error we should have sent ExitFailed. Furthermore, if we destroy the transaction object before QDBusPendingCallWatcher fires, we might lose that event.
1 parent c0aae36 commit 3c94288

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/transactionprivate.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,18 @@ void TransactionPrivate::runQueuedTransaction()
188188
return;
189189
}
190190

191-
if (reply.isFinished() && reply.isError()) {
192-
q->errorCode(Transaction::ErrorInternalError, reply.error().message());
193-
finished(Transaction::ExitFailed, 0);
191+
if (reply.isFinished()) {
192+
receivedReply = true;
193+
if (reply.isError()) {
194+
q->errorCode(Transaction::ErrorInternalError, reply.error().message());
195+
finished(Transaction::ExitFailed, 0);
196+
}
194197
return;
195198
}
196199
auto watcher = new QDBusPendingCallWatcher(reply, q);
197200
q->connect(watcher, &QDBusPendingCallWatcher::finished,
198201
q, [this, q] (QDBusPendingCallWatcher *call) {
202+
receivedReply = true;
199203
QDBusPendingReply<> reply = *call;
200204
if (reply.isError()) {
201205
QDBusError error = reply.error();
@@ -204,6 +208,8 @@ void TransactionPrivate::runQueuedTransaction()
204208
q->errorCode(transactionError, error.message());
205209
finished(Transaction::ExitFailed, 0);
206210
destroy();
211+
} else if (destroyOnReply) {
212+
destroy();
207213
}
208214
call->deleteLater();
209215
});
@@ -248,6 +254,12 @@ void TransactionPrivate::finished(uint exitCode, uint runtime)
248254
void TransactionPrivate::destroy()
249255
{
250256
Q_Q(Transaction);
257+
258+
if (!receivedReply) {
259+
destroyOnReply = true;
260+
return;
261+
}
262+
251263
if (p) {
252264
delete p;
253265
p = nullptr;

src/transactionprivate.h

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class TransactionPrivate
8282
uint uid = 0;
8383
QString senderName;
8484
bool sentFinished = false;
85+
bool receivedReply = false;
86+
bool destroyOnReply = false;
8587
bool allowCancel = false;
8688
bool callerActive = false;
8789

0 commit comments

Comments
 (0)