From a95a934344cd1288d539b4f1d50e993f0eb13c70 Mon Sep 17 00:00:00 2001 From: yeshanshan Date: Tue, 10 Mar 2026 21:31:56 +0800 Subject: [PATCH] fix: replace raw pointers with QPointer to prevent wild pointers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed raw QWaylandSurface pointers to QPointer smart pointers in PluginManagerExtensionPrivate and PluginManagerExtension classes to prevent wild pointer issues. This ensures automatic nullification when the referenced QWaylandSurface objects are destroyed, preventing crashes and undefined behavior. The raw pointers were vulnerable to becoming wild pointers if the QWaylandSurface objects were deleted while still being referenced. Using QPointer provides safe weak referencing with automatic null checks, improving memory safety and stability. Influence: 1. Test plugin management functionality with dynamic surface creation and destruction 2. Verify no crashes occur when surfaces are removed while being referenced 3. Test docking panel behavior with multiple plugin instances 4. Validate memory safety during compositor operations 5. Check for any regression in plugin loading/unloading fix: 使用 QPointer 替换原始指针以防止野指针问题 将 PluginManagerExtensionPrivate 和 PluginManagerExtension 类中的原始 QWaylandSurface 指针替换为 QPointer 智能指针,以防止野指针问题。这确保当 引用的 QWaylandSurface 对象被销毁时自动置空,防止崩溃和未定义行为。 原始指针在引用的 QWaylandSurface 对象被删除时容易变成野指针。使用 QPointer 提供安全的弱引用和自动空值检查,提高了内存安全性和稳定性。 ``` #0 0x00007f906aeedae6 in QList::size (this=) at /usr/include/x86_64-linux-gnu/qt6/QtCore/qlist.h:399 #1 QtPrivate::indexOf (from=, u=, vector=) at /usr/include/x86_64-linux-gnu/qt6/QtCore/qlist.h:933 #2 QListSpecialMethodsBase::indexOf (from=, t=, this=, this=, t=, from=) at /usr/include/x86_64-linux-gnu/qt6/QtCore/qlist.h:966 #3 QListSpecialMethodsBase::contains (t=, this=, this=, t=) at /usr/include/x86_64-linux-gnu/qt6/QtCore/qlist.h:48 #4 QWaylandSurfacePrivate::refView (this=0x18, view=view@entry=0x55879c897370) at ./src/compositor/compositor_api/qwaylandsurface.cpp:1014 #5 0x00007f906aef1403 in QWaylandViewPrivate::setSurface (this=0x55879c897390, newSurface=) at ./src/compositor/compositor_api/qwaylandview.cpp:121 #5 0x00007f906aef1403 in QWaylandViewPrivate::setSurface (this=0x55879c897390, newSurface=) at ./src/compositor/compositor_api/qwaylandview.cpp:121 de/x86_64-linux-gnu/qt6/QtCore/qlist.h:48 #6 0x00007f906aef1498 in QWaylandView::setSurface (this=0x55879c897370, newSurface=) at ./src/compositor/compositor_api/qwaylandview.cpp:141 #7 0x00007f906af47b06 in QWaylandQuickItem::setSurface (this=0x55879c897010, surface=0x55879c55e060) at ./src/compositor/compositor_api/qwaylandquickitem.cpp:560 #8 0x00007f908006733d in PluginManagerIntegration::PluginManagerIntegration (this=this@entry=0x55879c4745a0, item=item@entry=0x55879c897010) at ./panels/dock/pluginmanagerintegration.cpp:16 #9 0x00007f9080060d25 in PluginSurface::createIntegration (this=, item=0x55879c897010) at ./panels/dock/pluginmanagerextension.cpp:187 #10 0x00007f906af5074d in QWaylandQuickShellSurfaceItem::setShellSurface (this=0x55879c897010, shellSurface=0x55879c55cf10) at ./src/compositor/extensions/qwaylandquickshellsurfaceitem.cpp:117 ``` Influence: 1. 测试动态表面创建和销毁时的插件管理功能 2. 验证当表面被删除时仍被引用时不会发生崩溃 3. 测试多个插件实例时的停靠面板行为 4. 验证合成器操作期间的内存安全性 5. 检查插件加载/卸载功能是否有回归问题 --- panels/dock/pluginmanagerextension_p.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/panels/dock/pluginmanagerextension_p.h b/panels/dock/pluginmanagerextension_p.h index 709e2b375..4df253400 100644 --- a/panels/dock/pluginmanagerextension_p.h +++ b/panels/dock/pluginmanagerextension_p.h @@ -4,12 +4,13 @@ #pragma once -#include -#include +#include #include -#include +#include #include #include +#include +#include #include @@ -195,7 +196,7 @@ class PluginSurface : public QWaylandShellSurfaceTemplate, public private: PluginManager* m_manager; - QWaylandSurface* m_surface; + QPointer m_surface; QString m_itemKey; QString m_pluginId; @@ -269,7 +270,7 @@ class PluginPopup : public QWaylandShellSurfaceTemplate, public QtW private: PluginManager* m_manager; - QWaylandSurface* m_surface; + QPointer m_surface; QString m_itemKey; QString m_pluginId;