Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Verbruggen <erik@verbruggen.consulting>2021-10-15 15:05:01 +0300
committerErik Verbruggen <Erik.Verbruggen@Me.com>2021-12-03 12:45:08 +0300
commit470bf76e6362a4379e6548e466971e3a2e532ccd (patch)
treef697e03da9fde7e1d97394d867c6c3eed7f314d9 /src/gui/accountstate.cpp
parented603153da4fdc385f90982c88660fe0cec2f7ea (diff)
Use the refcounted AccountStatePtr as much as possible
The AccountManager creates AccountState objects, and stores them in a shared pointer. Previously, the raw pointer was given out, and stored in other objects. That made removal very tricky: when an account gets removed, the underlying object gets deleted, and then all classes that listen get notified of the deletion. Those classes would sometimes put a nullptr into the AccountState pointer they stored, and in each usage would (hopefully) check for a nullptr. The problem was that a number of checks were missing, which the clang static analyser pointed out. This patch changes nearly all uses of a raw pointer into the shared pointer, thereby making sure all usages have a valid reference, even when account deletion happens. The two places where a raw pointer is still used, now put it into a refcounted pointer as soon as possible.
Diffstat (limited to 'src/gui/accountstate.cpp')
-rw-r--r--src/gui/accountstate.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp
index 0243130ec..a95690e44 100644
--- a/src/gui/accountstate.cpp
+++ b/src/gui/accountstate.cpp
@@ -128,9 +128,9 @@ AccountState::~AccountState()
{
}
-AccountState *AccountState::loadFromSettings(AccountPtr account, const QSettings &settings)
+AccountStatePtr AccountState::loadFromSettings(AccountPtr account, const QSettings &settings)
{
- auto accountState = new AccountState(account);
+ auto accountState = AccountStatePtr(new AccountState(account));
const bool userExplicitlySignedOut = settings.value(userExplicitlySignedOutC(), false).toBool();
if (userExplicitlySignedOut) {
// see writeToSettings below
@@ -139,6 +139,11 @@ AccountState *AccountState::loadFromSettings(AccountPtr account, const QSettings
return accountState;
}
+AccountStatePtr AccountState::fromNewAccount(AccountPtr account)
+{
+ return AccountStatePtr(new AccountState(account));
+}
+
void AccountState::writeToSettings(QSettings &settings) const
{
// The SignedOut state is the only state where the client should *not* ask for credentials, nor