Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/seat/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ Helper::Helper(QObject *parent)
m_instance = this;

Q_ASSERT(!m_config);
m_config = TreelandUserConfig::createByName("org.deepin.dde.treeland.user",
m_config.reset(TreelandUserConfig::createByName("org.deepin.dde.treeland.user",
"org.deepin.dde.treeland",
"/dde"); // will update user path in Helper::init
"/dde")); // will update user path in Helper::init
m_globalConfig.reset(TreelandConfig::create("org.deepin.dde.treeland",
QString()));

Comment on lines +215 to 220
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Resetting the unique_ptr may invalidate external raw pointers to the config.

With the raw pointer, reassigning m_config leaked the old instance but didn’t invalidate any cached raw pointers. Using std::unique_ptr::reset() now correctly deletes the old config, so any code that has stored a Helper::config() pointer will end up with a dangling pointer after updateCurrentUser. Callers should not cache this pointer long-term, or config() should expose a safer API (e.g., reference or handle) that makes ownership and lifetime explicit.

Expand Down Expand Up @@ -310,7 +310,7 @@ Helper *Helper::instance()

TreelandUserConfig *Helper::config()
{
return m_config;
return m_config.get();
}

TreelandConfig *Helper::globalConfig()
Expand Down Expand Up @@ -1324,9 +1324,9 @@ void Helper::init(Treeland::Treeland *treeland)
m_personalization = m_server->attach<PersonalizationV1>();

auto updateCurrentUser = [this] {
m_config = TreelandUserConfig::createByName("org.deepin.dde.treeland.user",
m_config.reset(TreelandUserConfig::createByName("org.deepin.dde.treeland.user",
"org.deepin.dde.treeland",
"/" + m_userModel->currentUserName());
"/" + m_userModel->currentUserName()));
auto user = m_userModel->currentUser();
m_personalization->setUserId(user ? user->UID() : getuid());
};
Expand Down
2 changes: 1 addition & 1 deletion src/seat/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private Q_SLOTS:
bool isXWaylandClient(WClient *client);

static Helper *m_instance;
TreelandUserConfig *m_config = nullptr;
std::unique_ptr<TreelandUserConfig> m_config;
std::unique_ptr<TreelandConfig> m_globalConfig;
Treeland::Treeland *m_treeland = nullptr;
FpsDisplayManager *m_fpsManager = nullptr;
Expand Down