Commit 53574eb6 authored by Ahmad Samir's avatar Ahmad Samir

AgentBase: Fix crash in setOnline

When setOnline tries to access the mSettings member after the latter has
been deleted we get a crash; mSettings is deleted in quit() or cleanup(),
therefore it looks like a race condition: the Agent is about to quit, but
some other code calls setOnline leading to a crash. It looks like this can
happen in more than one way, e.g. via a dbus call (from AgentInstance), or
via a sub-class of AgentBase calling setOnline directly. Use a bool member
var, modelled after how AgentInstance uses a similar logic.

BUG: 418844
parent 8c3d1f3b
Pipeline #32681 passed with stage
in 41 minutes and 3 seconds
......@@ -333,6 +333,7 @@ AgentBasePrivate::AgentBasePrivate(AgentBase *parent)
, mNeedsNetwork(false)
, mOnline(false)
, mDesiredOnlineState(false)
, mPendingQuit(false)
, mSettings(nullptr)
, mChangeRecorder(nullptr)
, mTracer(nullptr)
......@@ -1006,6 +1007,11 @@ void AgentBase::setNeedsNetwork(bool needsNetwork)
void AgentBase::setOnline(bool state)
{
Q_D(AgentBase);
if (d->mPendingQuit) {
return;
}
d->mDesiredOnlineState = state;
d->mSettings->setValue(QStringLiteral("Agent/DesiredOnlineState"), state);
setOnlineInternal(state);
......@@ -1126,6 +1132,8 @@ void AgentBase::quit()
void AgentBase::aboutToQuit()
{
Q_D(AgentBase);
d->mPendingQuit = true;
}
void AgentBase::cleanup()
......
......@@ -88,6 +88,8 @@ public:
bool mOnline;
bool mDesiredOnlineState;
bool mPendingQuit;
QSettings *mSettings = nullptr;
ChangeRecorder *mChangeRecorder = nullptr;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment