Skip to content

fix: prevent crash on toplevel destruction#1647

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
18202781743:master
Jun 23, 2026
Merged

fix: prevent crash on toplevel destruction#1647
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743

Copy link
Copy Markdown
Contributor

Added proper destructor to ForeignToplevelHandle class to
clean up the Wayland object when the instance is destroyed.
Previously, the destructor was missing, causing the underlying
treeland_foreign_toplevel_handle_v1 object to remain alive after the
ForeignToplevelHandle wrapper was destroyed, leading to use-after-free
crashes in the task manager.

The fix ensures that when a ForeignToplevelHandle is destroyed, its
associated Wayland protocol object is properly destroyed via the
destroy() method, preventing dangling pointers and toplevel crashes.

Log: Fixed crash when closing windows in the dock task manager

Influence:

  1. Open and close multiple applications rapidly to trigger toplevel
    destroy events
  2. Test with applications that create and destroy windows frequently
  3. Verify dock task manager remains stable during window management
    operations
  4. Test with different types of windows (normal, dialog, transient)

fix: 修复顶层窗口销毁时的崩溃问题

为 ForeignToplevelHandle 类添加了正确的析构函数,在实例销毁时清理
Wayland 对象。之前缺少析构函数,导致 ForeignToplevelHandle 包装类销毁
后,底层的 treeland_foreign_toplevel_handle_v1 对象仍然存在,导致任务管
理器出现释放后使用崩溃。

该修复确保了 ForeignToplevelHandle 被销毁时,其关联的 Wayland 协议对象通
destroy() 方法被正确销毁,防止悬空指针和顶层窗口崩溃。

Log: 修复关闭dock任务管理器中窗口时的崩溃问题

Influence:

  1. 快速打开和关闭多个应用程序以触发顶层窗口销毁事件
  2. 测试频繁创建和销毁窗口的应用程序
  3. 验证窗口管理操作期间dock任务管理器的稳定性
  4. 测试不同类型的窗口(普通窗口、对话框、临时窗口)

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @18202781743, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@18202781743

Copy link
Copy Markdown
Contributor Author

gdb) bt
#0 0x00007f4b286b1437 in QtWayland::treeland_foreign_toplevel_handle_v1::handle_app_id(void*, treeland_foreign_toplevel_handle_v1*, char const*) ()
at /usr/lib/x86_64-linux-gnu/dde-shell/org.deepin.ds.dock.taskmanager.so
#1 0x00007f4b30c2d36e in ??? () at /lib/x86_64-linux-gnu/libffi.so.8
#2 0x00007f4b30c2c65d in ??? () at /lib/x86_64-linux-gnu/libffi.so.8
#3 0x00007f4b30c2ce53 in ffi_call () at /lib/x86_64-linux-gnu/libffi.so.8
#4 0x00007f4b331e3cf6 in wl_closure_invoke (closure=closure@entry=0x7f4b1c003d80, flags=flags@entry=1, target=,
target@entry=0x7f4b14002330, opcode=opcode@entry=2, data=) at ../src/connection.c:1228
#5 0x00007f4b331dfc2f in dispatch_event (display=display@entry=0x55b75b15ec40, queue=queue@entry=0x55b75b15ed38) at ../src/wayland-client.c:1674
#6 0x00007f4b331e0f53 in dispatch_queue (queue=0x55b75b15ed38, display=0x55b75b15ec40) at ../src/wayland-client.c:1820
#7 wl_display_dispatch_queue_pending (display=0x55b75b15ec40, queue=0x55b75b15ed38) at ../src/wayland-client.c:2062
#8 0x00007f4b3430b505 in QtWaylandClient::QWaylandDisplay::flushRequests() () at /lib/x86_64-linux-gnu/libQt6WaylandClient.so.6
#9 0x00007f4b31b5d91f in QObject::event(QEvent*) () at /lib/x86_64-linux-gnu/libQt6Core.so.6
#10 0x00007f4b32937025 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /lib/x86_64-linux-gnu/libQt6Widgets.so.6
#11 0x00007f4b31b1aeb8 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /lib/x86_64-linux-gnu/libQt6Core.so.6
#12 0x00007f4b31b22d77 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () at /lib/x86_64-linux-gnu/libQt6Core.so.6
#13 0x00007f4b31d12507 in ??? () at /lib/x86_64-linux-gnu/libQt6Core.so.6
#14 0x00007f4b30b33869 in ??? () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#15 0x00007f4b30b35967 in ??? () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#16 0x00007f4b30b35f70 in g_main_context_iteration () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#17 0x00007f4b31d0fd50 in QEventDispatcherGlib::processEvents(QFlagsQEventLoop::ProcessEventsFlag) () at /lib/x86_64-linux-gnu/libQt6Core.so.6
#18 0x00007f4b31b23c2a in QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) () at /lib/x86_64-linux-gnu/libQt6Core.so.6
#19 0x00007f4b31b1dce8 in QCoreApplication::exec() () at /lib/x86_64-linux-gnu/libQt6Core.so.6
#20 0x000055b7495c61cf in main ()
(gdb)

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, BLumia

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Added proper destructor to ForeignToplevelHandle class to
clean up the Wayland object when the instance is destroyed.
Previously, the destructor was missing, causing the underlying
treeland_foreign_toplevel_handle_v1 object to remain alive after the
ForeignToplevelHandle wrapper was destroyed, leading to use-after-free
crashes in the task manager.

The fix ensures that when a ForeignToplevelHandle is destroyed, its
associated Wayland protocol object is properly destroyed via the
`destroy()` method, preventing dangling pointers and toplevel crashes.

Log: Fixed crash when closing windows in the dock task manager

Influence:
1. Open and close multiple applications rapidly to trigger toplevel
destroy events
2. Test with applications that create and destroy windows frequently
3. Verify dock task manager remains stable during window management
operations
4. Test with different types of windows (normal, dialog, transient)

fix: 修复顶层窗口销毁时的崩溃问题

为 ForeignToplevelHandle 类添加了正确的析构函数,在实例销毁时清理
Wayland 对象。之前缺少析构函数,导致 ForeignToplevelHandle 包装类销毁
后,底层的 treeland_foreign_toplevel_handle_v1 对象仍然存在,导致任务管
理器出现释放后使用崩溃。

该修复确保了 ForeignToplevelHandle 被销毁时,其关联的 Wayland 协议对象通
过 `destroy()` 方法被正确销毁,防止悬空指针和顶层窗口崩溃。

Log: 修复关闭dock任务管理器中窗口时的崩溃问题

Influence:
1. 快速打开和关闭多个应用程序以触发顶层窗口销毁事件
2. 测试频繁创建和销毁窗口的应用程序
3. 验证窗口管理操作期间dock任务管理器的稳定性
4. 测试不同类型的窗口(普通窗口、对话框、临时窗口)
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码精准修复了Wayland代理对象未初始化与资源泄漏问题,质量优秀
逻辑完全正确且符合规范,无任何扣分项

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

ForeignToplevelHandle 构造函数中补充了 m_identifier(0) 初始化,消除了野值返回风险;新增的析构函数通过 if (object()) 判空后调用 destroy(),安全释放了底层的 treeland_foreign_toplevel_handle_v1 代理对象,逻辑严密无缺陷。
建议:保持当前的防御性编程风格。

  • 2.代码质量(良好)✓

代码改动精简干练,头文件与源文件修改保持同步。遵循了C++ RAII原则,有效补充了资源生命周期管理,符合QtWayland扩展类的标准实现规范。
建议:无需额外修改。

  • 3.代码性能(无性能问题)✓

析构函数中的 object() 检查仅为一次指针读取判断,destroy() 释放操作属于必要的系统调用开销,不存在任何冗余计算或性能瓶颈。
建议:无需额外修改。

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次代码修改消除了原有的未初始化内存读取和悬空指针风险,未引入任何新的安全漏洞,整体安全性高。
建议:继续保持对Wayland代理对象生命周期的严格管理。

■ 【改进建议代码示例】

// 当前代码已为最佳实践,无需额外修改,以下为完整确认示例
// treelandwindow.h
class ForeignToplevelHandle : public QWaylandClientExtensionTemplate<ForeignToplevelHandle> {
public:
    explicit ForeignToplevelHandle(struct ::treeland_foreign_toplevel_handle_v1 *object);
    ~ForeignToplevelHandle();
    // ...
};

// treelandwindow.cpp
ForeignToplevelHandle::ForeignToplevelHandle(struct ::treeland_foreign_toplevel_handle_v1 *object)
    : QtWayland::treeland_foreign_toplevel_handle_v1(object)
    , m_pid(0)
    , m_isReady(false)
    , m_identifier(0)
{
    init(object);
}

ForeignToplevelHandle::~ForeignToplevelHandle()
{
    if (object()) {
        destroy();
    }
}

@18202781743

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot deepin-bot Bot merged commit cbd22f2 into linuxdeepin:master Jun 23, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants