Skip to content

Commit

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

if (reply.isFinished() && reply.isError()) {
q->errorCode(Transaction::ErrorInternalError, reply.error().message());
finished(Transaction::ExitFailed, 0);
if (reply.isFinished()) {
receivedReply = true;
if (reply.isError()) {
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) {
receivedReply = true;
QDBusPendingReply<> reply = *call;
if (reply.isError()) {
QDBusError error = reply.error();
Expand All @@ -204,6 +208,8 @@ void TransactionPrivate::runQueuedTransaction()
q->errorCode(transactionError, error.message());
finished(Transaction::ExitFailed, 0);
destroy();
} else if (destroyOnReply) {
destroy();
}
call->deleteLater();
});
Expand Down Expand Up @@ -248,6 +254,12 @@ void TransactionPrivate::finished(uint exitCode, uint runtime)
void TransactionPrivate::destroy()
{
Q_Q(Transaction);

if (!receivedReply) {
destroyOnReply = 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 receivedReply = false;
bool destroyOnReply = false;
bool allowCancel = false;
bool callerActive = false;

Expand Down

0 comments on commit 3c94288

Please sign in to comment.