Skip to content

Commit 87b7184

Browse files
committed
fix: replace raw pointers with QPointer to prevent wild pointers
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<QWaylandView*>::size (this=<optimized out>) at /usr/include/x86_64-linux-gnu/qt6/QtCore/qlist.h:399 #1 QtPrivate::indexOf<QWaylandView*, QWaylandView*> (from=<optimized out>, u=<optimized out>, vector=<optimized out>) at /usr/include/x86_64-linux-gnu/qt6/QtCore/qlist.h:933 #2 QListSpecialMethodsBase<QWaylandView*>::indexOf<QWaylandView*> (from=<optimized out>, t=<optimized out>, this=<optimized out>, this=<optimized out>, t=<optimized out>, from=<optimized out>) at /usr/include/x86_64-linux-gnu/qt6/QtCore/qlist.h:966 #3 QListSpecialMethodsBase<QWaylandView*>::contains<QWaylandView*> (t=<optimized out>, this=<optimized out>, this=<optimized out>, t=<optimized out>) 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=<optimized out>) at ./src/compositor/compositor_api/qwaylandview.cpp:121 #5 0x00007f906aef1403 in QWaylandViewPrivate::setSurface (this=0x55879c897390, newSurface=<optimized out>) 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=<optimized out>) 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=<optimized out>, 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. 检查插件加载/卸载功能是否有回归问题
1 parent 1d96fad commit 87b7184

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

panels/dock/pluginmanagerextension_p.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
#pragma once
66

7-
#include <QtWaylandCompositor/QWaylandShellSurfaceTemplate>
8-
#include <QtWaylandCompositor/QWaylandQuickExtension>
7+
#include <QPointer>
98
#include <QtWaylandCompositor/QWaylandCompositor>
10-
#include <QtWaylandCompositor/QWaylandSurface>
9+
#include <QtWaylandCompositor/QWaylandQuickExtension>
1110
#include <QtWaylandCompositor/QWaylandResource>
1211
#include <QtWaylandCompositor/QWaylandSeat>
12+
#include <QtWaylandCompositor/QWaylandShellSurfaceTemplate>
13+
#include <QtWaylandCompositor/QWaylandSurface>
1314

1415
#include <cstdint>
1516

@@ -195,7 +196,7 @@ class PluginSurface : public QWaylandShellSurfaceTemplate<PluginSurface>, public
195196

196197
private:
197198
PluginManager* m_manager;
198-
QWaylandSurface* m_surface;
199+
QPointer<QWaylandSurface> m_surface;
199200

200201
QString m_itemKey;
201202
QString m_pluginId;
@@ -269,7 +270,7 @@ class PluginPopup : public QWaylandShellSurfaceTemplate<PluginPopup>, public QtW
269270

270271
private:
271272
PluginManager* m_manager;
272-
QWaylandSurface* m_surface;
273+
QPointer<QWaylandSurface> m_surface;
273274

274275
QString m_itemKey;
275276
QString m_pluginId;

0 commit comments

Comments
 (0)