Skip to content

Commit 3af1d42

Browse files
committed
fix: prevent dangling pointer in XembedProtocol::onRemoveItemByPid
1. Fixed a potential dangling pointer issue by storing m_registedItem.keys() in a local variable 2. Previously used m_registedItem.keys() directly which could become invalid after container modification 3. Now using a const copy of keys to ensure stable iteration during item removal 4. This prevents crashes when removing items from the tray icon registry Influence: 1. Test tray icon removal functionality when applications exit 2. Verify no crashes occur during dynamic tray icon updates 3. Test with multiple tray icons being added and removed simultaneously 4. Verify tray icon registry remains stable during container modifications fix: 修复 XembedProtocol::onRemoveItemByPid 中的野指针问题 1. 通过将 m_registedItem.keys() 存储在局部变量中修复了潜在的野指针问题 2. 之前直接使用 m_registedItem.keys(),在容器修改后可能变为无效 3. 现在使用 keys 的常量副本以确保在移除项目期间迭代的稳定性 4. 这防止了从托盘图标注册表中移除项目时发生崩溃 Influence: 1. 测试应用程序退出时的托盘图标移除功能 2. 验证在动态托盘图标更新期间不会发生崩溃 3. 测试多个托盘图标同时添加和移除的情况 4. 验证托盘图标注册表在容器修改期间保持稳定
1 parent 50a5097 commit 3af1d42

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

plugins/application-tray/xembedprotocolhandler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -115,8 +115,9 @@ void XembedProtocol::onTrayIconsChanged()
115115

116116
void XembedProtocol::onRemoveItemByPid(uint pid)
117117
{
118-
auto it = std::find_if(m_registedItem.keys().begin(), m_registedItem.keys().end(), [this, pid] (uint id) { return pid == m_item2Pid[id]; });
119-
if (it != m_registedItem.keys().end()) {
118+
const auto keys = m_registedItem.keys();
119+
auto it = std::find_if(keys.begin(), keys.end(), [this, pid] (uint id) { return pid == m_item2Pid[id]; });
120+
if (it != keys.end()) {
120121
m_item2Pid.remove(*it);
121122
m_registedItem.remove(*it);
122123
}

0 commit comments

Comments
 (0)