Repository navigation
fix: avoid StartManager singleton creation in destructor - #637
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThe PR fixes shutdown crashes in secondary editor processes by preventing EditorApplication’s destructor from lazily creating a StartManager singleton when none exists, while preserving deletion of an existing instance. Sequence diagram for safe editor shutdownsequenceDiagram
participant EditorApplication
participant StartManager
EditorApplication->>StartManager: instanceOrNull()
StartManager-->>EditorApplication: m_instance
alt existing instance
EditorApplication->>StartManager: delete
StartManager-->>EditorApplication: destructor completes
else no instance
EditorApplication->>EditorApplication: skip deletion
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
f098b3a to
76e9fd4
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 语法正确,逻辑清晰,边界处理完善 2. 代码质量 ✅评价: 优秀 ✅ 通过 潜在问题:
建议: 建议在 instanceOrNull() 方法上方添加简短注释,说明与 instance() 的区别(只读访问,不创建实例);析构函数中可将 instanceOrNull() 结果存储到局部变量避免重复调用 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题:
建议: 将 instanceOrNull() 结果存储到局部变量,减少一次函数调用 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 无安全漏洞,安全合规 💡 改进建议代码示例// 析构函数优化:避免重复调用 instanceOrNull()
EditorApplication::~EditorApplication()
{
qDebug() << "Enter EditorApplication destructor";
StartManager *mgr = StartManager::instanceOrNull();
if (mgr) {
qDebug() << "Deleting StartManager instance";
delete mgr;
} else {
qDebug() << "StartManager instance is already null";
}
qDebug() << "Exit EditorApplication destructor";
}本报告由 AI 代码审查工具自动生成 |
1. Root cause: StartManager::instance() lazily creates the singleton,
and ~EditorApplication() called it during teardown; a forwarding
(second) process that never created StartManager would instantiate
a full instance (login1 inhibit D-Bus call, QTimer, Iflytek AI
probe QtConcurrent task) and destroy it right away, leaving the
worker thread logging during process teardown and crashing in
libdtk6log (SIGSEGV)
2. Fix:
- instance() is now a pure non-creating accessor
- creation is explicit via create(), called exactly once in main()
- the first (service-owning) process releases the singleton in
main() right after the event loop ends; ~EditorApplication()
no longer touches StartManager at all
3. Impact: the forwarding process exit path never instantiates
StartManager, removing the teardown crash; accidental singleton
creation is now impossible for all callers by construction
Log: Fixed crash when opening a text file from desktop with the editor already running
Influence:
1. Test opening a text file by double-clicking on desktop with editor open
2. Test launching a second instance that forwards files via D-Bus
3. Test single-window startup and normal exit of the editor
4. Run StartManager / EditorApplication / Window / Controls unit tests
(updated for create() / non-creating instance() semantics)
fix: 单例生命周期显式化,修复退出崩溃
1. 根因: StartManager::instance() 是懒创建访问器,~EditorApplication()
在退出期调用它;D-Bus 转发进程从未创建过单例,析构时意外实例化完整
StartManager(login1 inhibit 同步 D-Bus 调用、QTimer、Iflytek AI 探测
QtConcurrent 任务)并立即销毁,工作线程在进程 teardown 期间打日志,
于 libdtk6log 中 SIGSEGV
2. 方案:
- instance() 改为纯查询访问器,不再有创建副作用
- 创建显式化为 create(),仅在 main() 中调用一次
- 首进程在事件循环结束后于 main() 中显式释放单例,
~EditorApplication() 不再触碰 StartManager
3. 影响: 转发进程退出路径不再实例化 StartManager,消除崩溃;对所有
调用方而言,意外创建单例在构造上已不可能
Log: 修复已打开编辑器时双击桌面文本文档产生的崩溃
Influence:
1. 测试已打开编辑器时双击桌面文本文档
2. 测试第二进程通过 D-Bus 转发文件后退出
3. 测试单窗口启动与正常退出
4. 运行 StartManager / EditorApplication / Window / Controls 单元测试
(已随 create() / 非创建 instance() 语义同步更新)
PMS: BUG-378901
76e9fd4 to
8d0e4a3
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, pengfeixx The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
fix: avoid StartManager singleton creation in destructor
which lazily creates a new singleton when m_instance is null
without creating, use it in destructor for null-check and delete
longer triggers spurious StartManager creation/destruction crash
Log: Fixed crash when closing editor after opening text file from desktop
Influence:
fix: 修复析构函数中单例懒加载创建导致的崩溃
m_instance 为 null 时会懒加载创建新实例
访问器,析构函数改用该方法判空和删除
StartManager 导致 SIGSEGV
Log: 修复双击桌面文本文档时文本编辑器崩溃的问题
Influence:
PMS: BUG-378901
Summary by Sourcery
Prevent StartManager from being created during editor destruction and ensure its lifecycle is managed explicitly during normal application startup and shutdown.
Bug Fixes:
Enhancements:
Tests: