Skip to content

Commit 8566148

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 8566148

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/transactionprivate.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,19 @@ 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
}
196200
auto watcher = new QDBusPendingCallWatcher(reply, q);
197201
q->connect(watcher, &QDBusPendingCallWatcher::finished,
198202
q, [this, q] (QDBusPendingCallWatcher *call) {
203+
receivedReturn = true;
199204
QDBusPendingReply<> reply = *call;
200205
if (reply.isError()) {
201206
QDBusError error = reply.error();
@@ -204,6 +209,8 @@ void TransactionPrivate::runQueuedTransaction()
204209
q->errorCode(transactionError, error.message());
205210
finished(Transaction::ExitFailed, 0);
206211
destroy();
212+
} else if (destroyOnReturn) {
213+
destroy();
207214
}
208215
call->deleteLater();
209216
});
@@ -248,6 +255,12 @@ void TransactionPrivate::finished(uint exitCode, uint runtime)
248255
void TransactionPrivate::destroy()
249256
{
250257
Q_Q(Transaction);
258+
259+
if (!receivedReturn) {
260+
destroyOnReturn = true;
261+
return;
262+
}
263+
251264
if (p) {
252265
delete p;
253266
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)