Skip to content

Commit

Permalink
Do not destroy the transaction before it has returned
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aleasto committed Jul 21, 2023
1 parent c0aae36 commit 8566148
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/transactionprivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,19 @@ void TransactionPrivate::runQueuedTransaction()
return;
}

if (reply.isFinished() && reply.isError()) {
q->errorCode(Transaction::ErrorInternalError, reply.error().message());
finished(Transaction::ExitFailed, 0);
if (reply.isFinished()) {
receivedReturn = true;
if (reply.isError()) {
receivedReturn = true;
q->errorCode(Transaction::ErrorInternalError, reply.error().message());
finished(Transaction::ExitFailed, 0);
}
return;
}
auto watcher = new QDBusPendingCallWatcher(reply, q);
q->connect(watcher, &QDBusPendingCallWatcher::finished,
q, [this, q] (QDBusPendingCallWatcher *call) {
receivedReturn = true;
QDBusPendingReply<> reply = *call;
if (reply.isError()) {
QDBusError error = reply.error();
Expand All @@ -204,6 +209,8 @@ void TransactionPrivate::runQueuedTransaction()
q->errorCode(transactionError, error.message());
finished(Transaction::ExitFailed, 0);
destroy();
} else if (destroyOnReturn) {
destroy();
}
call->deleteLater();
});
Expand Down Expand Up @@ -248,6 +255,12 @@ void TransactionPrivate::finished(uint exitCode, uint runtime)
void TransactionPrivate::destroy()
{
Q_Q(Transaction);

if (!receivedReturn) {
destroyOnReturn = true;
return;
}

if (p) {
delete p;
p = nullptr;
Expand Down
2 changes: 2 additions & 0 deletions src/transactionprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class TransactionPrivate
uint uid = 0;
QString senderName;
bool sentFinished = false;
bool receivedReturn = false;
bool destroyOnReturn = false;
bool allowCancel = false;
bool callerActive = false;

Expand Down

0 comments on commit 8566148

Please sign in to comment.