Commit 66d1135d authored by Ahmad Samir's avatar Ahmad Samir
Browse files

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
(cherry picked from commit 53574eb6)
parent 2003c698
......@@ -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)
if (d->mPendingQuit) {
d->mDesiredOnlineState = state;
d->mSettings->setValue(QStringLiteral("Agent/DesiredOnlineState"), state);
......@@ -1126,6 +1132,8 @@ void AgentBase::quit()
void AgentBase::aboutToQuit()
d->mPendingQuit = true;
void AgentBase::cleanup()
......@@ -88,6 +88,8 @@ public:
bool mOnline;
bool mDesiredOnlineState;
bool mPendingQuit;
QSettings *mSettings = nullptr;
ChangeRecorder *mChangeRecorder = nullptr;
Supports Markdown
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