Skip to content

Commit 62ae20b

Browse files
authored
[DC-81] fix: leak of AccountState (#12254)
Fix leak of `AccountState`
1 parent d34136f commit 62ae20b

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/gui/accountmanager.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,7 @@ bool AccountManager::accountForLoginExists(const QUrl &url, const QString &davUs
321321

322322
QList<AccountState *> AccountManager::accountsRaw() const
323323
{
324-
QList<AccountState *> out;
325-
out.reserve(_accounts.size());
326-
for (auto &x : _accounts) {
327-
out.append(x);
328-
}
329-
return out;
324+
return _accounts.values();
330325
}
331326

332327
AccountPtr AccountManager::loadAccountHelper(QSettings &settings)
@@ -447,9 +442,20 @@ AccountPtr AccountManager::createAccount(const QUuid &uuid)
447442
void AccountManager::shutdown()
448443
{
449444
const auto accounts = std::move(_accounts);
450-
for (const auto &acc : accounts) {
445+
for (AccountState *acc : accounts) {
451446
Q_EMIT accountRemoved(acc);
447+
delete acc;
448+
}
449+
}
450+
451+
const QList<AccountStatePtr> AccountManager::accounts() const
452+
{
453+
QList<AccountStatePtr> ptrs;
454+
ptrs.reserve(_accounts.size());
455+
for (AccountState *acc : _accounts) {
456+
ptrs.append(acc);
452457
}
458+
return ptrs;
453459
}
454460

455461
bool AccountManager::isAccountIdAvailable(const QString &id) const

src/gui/accountmanager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class OWNCLOUDGUI_EXPORT AccountManager : public QObject
7878
/**
7979
* Return a list of all accounts.
8080
*/
81-
const QList<AccountStatePtr> accounts() const { return _accounts.values(); }
81+
const QList<AccountStatePtr> accounts() const;
8282

8383
/**
8484
* Return the account state pointer for an account identified by its display name
@@ -144,7 +144,7 @@ public Q_SLOTS:
144144

145145
private:
146146
AccountManager() {}
147-
QMap<QUuid, AccountStatePtr> _accounts;
147+
QMap<QUuid, AccountState *> _accounts;
148148
/// Account ids from settings that weren't read
149149
QSet<QString> _additionalBlockedAccountIds;
150150
};

0 commit comments

Comments
 (0)