Skip to content

Commit c2f9d18

Browse files
committed
Do not destroy the transaction before it has returned
Destroy might be signaled before the dbus call has returned. 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 c2f9d18

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/transactionprivate.cpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,20 @@ 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+
receivedReturn = true;
193+
if (reply.isError()) {
194+
receivedReturn = true;
195+
q->errorCode(Transaction::ErrorInternalError, reply.error().message());
196+
finished(Transaction::ExitFailed, 0);
197+
}
194198
return;
195199
}
200+
196201
auto watcher = new QDBusPendingCallWatcher(reply, q);
197202
q->connect(watcher, &QDBusPendingCallWatcher::finished,
198203
q, [this, q] (QDBusPendingCallWatcher *call) {
204+
receivedReturn = true;
199205
QDBusPendingReply<> reply = *call;
200206
if (reply.isError()) {
201207
QDBusError error = reply.error();
@@ -204,6 +210,8 @@ void TransactionPrivate::runQueuedTransaction()
204210
q->errorCode(transactionError, error.message());
205211
finished(Transaction::ExitFailed, 0);
206212
destroy();
213+
} else if (destroyOnReturn) {
214+
destroy();
207215
}
208216
call->deleteLater();
209217
});
@@ -248,6 +256,12 @@ void TransactionPrivate::finished(uint exitCode, uint runtime)
248256
void TransactionPrivate::destroy()
249257
{
250258
Q_Q(Transaction);
259+
260+
if (!receivedReturn) {
261+
destroyOnReturn = true;
262+
return;
263+
}
264+
251265
if (p) {
252266
delete p;
253267
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 receivedReturn = false;
86+
bool destroyOnReturn = false;
8587
bool allowCancel = false;
8688
bool callerActive = false;
8789

0 commit comments

Comments
 (0)