Skip to content

fix: fix use-after-free in EditWrapper destructor - #639

Closed
pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/bug/5eec6c3eb615
Closed

pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/bug/5eec6c3eb615

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

fix: fix use-after-free in EditWrapper destructor

  1. Move deletion of m_pWaringNotices before m_pTextEdit in ~EditWrapper()
  2. DMessageManager holds a reference to m_pTextEdit via event filter
  3. Deleting m_pTextEdit first left DMessageManager with a dangling pointer
  4. Previous fix for bug 78042 commented out m_pWaringNotices deletion entirely
  5. Re-enable deletion with corrected order to fix both bug 378881 and 78042

Log: Fix crash when closing text document opened from a compressed archive

Influence:

  1. Test opening a text file from a zip archive, modifying and closing it
  2. Verify no crash log is generated after closing the document
  3. Test file reload prompt appears correctly when external modification occurs

fix: 修复 EditWrapper 析构函数中的 use-after-free 问题

  1. 在 ~EditWrapper() 中将 m_pWaringNotices 的删除移至 m_pTextEdit 之前
  2. DMessageManager 通过事件过滤器持有 m_pTextEdit 的引用
  3. 先删除 m_pTextEdit 会导致 DMessageManager 持有悬空指针
  4. 此前 bug 78042 的修复直接注释掉了 m_pWaringNotices 的删除
  5. 以正确顺序重新启用删除,同时修复 bug 378881 和避免 bug 78042 回归

Log: 修复压缩包中打开文本文档关闭后文本编辑器崩溃的问题

Influence:

  1. 测试从 zip 压缩包中打开文本文档,修改后关闭
  2. 验证关闭文档后不产生崩溃日志
  3. 测试文件被外部修改时重新加载提示框正常显示

PMS: BUG-378881

Summary by Sourcery

Fix EditWrapper destruction to clean up warning notices before the text editor and eliminate dangling event-filter references.

Bug Fixes:

  • Prevent crashes and use-after-free errors when closing text documents, including files opened from compressed archives.
  • Restore warning-notice cleanup while preserving correct file-reload prompt behavior.

1. Move deletion of m_pWaringNotices before m_pTextEdit in ~EditWrapper()
2. DMessageManager holds a reference to m_pTextEdit via event filter
3. Deleting m_pTextEdit first left DMessageManager with a dangling pointer
4. Previous fix for bug 78042 commented out m_pWaringNotices deletion entirely
5. Re-enable deletion with corrected order to fix both bug 378881 and 78042

Log: Fix crash when closing text document opened from a compressed archive

Influence:
1. Test opening a text file from a zip archive, modifying and closing it
2. Verify no crash log is generated after closing the document
3. Test file reload prompt appears correctly when external modification occurs

fix: 修复 EditWrapper 析构函数中的 use-after-free 问题

1. 在 ~EditWrapper() 中将 m_pWaringNotices 的删除移至 m_pTextEdit 之前
2. DMessageManager 通过事件过滤器持有 m_pTextEdit 的引用
3. 先删除 m_pTextEdit 会导致 DMessageManager 持有悬空指针
4. 此前 bug 78042 的修复直接注释掉了 m_pWaringNotices 的删除
5. 以正确顺序重新启用删除,同时修复 bug 378881 和避免 bug 78042 回归

Log: 修复压缩包中打开文本文档关闭后文本编辑器崩溃的问题

Influence:
1. 测试从 zip 压缩包中打开文本文档,修改后关闭
2. 验证关闭文档后不产生崩溃日志
3. 测试文件被外部修改时重新加载提示框正常显示

PMS: BUG-378881
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pengfeixx

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

@sourcery-ai

sourcery-ai Bot commented Oct 9, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The destructor now cleans up m_pWaringNotices before m_pTextEdit, ensuring DMessageManager no longer references a freed editor while preserving warning-notice cleanup and addressing the related crash regressions.

Sequence diagram for safe EditWrapper destruction

sequenceDiagram
    participant EditWrapper
    participant DMessageManager
    participant WarningNotices
    participant TextEdit

    EditWrapper->>WarningNotices: disconnect()
    EditWrapper->>WarningNotices: delete
    WarningNotices-->>DMessageManager: remove event filter
    EditWrapper->>TextEdit: disconnect()
    EditWrapper->>TextEdit: delete
    DMessageManager-->>TextEdit: no dangling reference
Loading

File-Level Changes

Change Details Files
Restores warning-notice cleanup and moves it ahead of text-editor destruction to prevent event-filter references from becoming dangling.
  • Disconnects and deletes m_pWaringNotices before m_pTextEdit.
  • Nulls the warning-notice pointer after deletion.
  • Removes the previously disabled cleanup block and documents the destructor-order dependency.
src/editor/editwrapper.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次变更修复了 EditWrapper 析构函数中的 use-after-free 问题,通过调整 m_pWaringNotices 和 m_pTextEdit 的删除顺序,避免了 DMessageManager 持有悬空指针导致的崩溃。代码逻辑正确,注释详尽,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 无


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 无


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 无


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 无


💡 改进建议代码示例

// 暂无代码示例

本报告由 AI 代码审查工具自动生成

@pengfeixx pengfeixx closed this by deleting the head repository Oct 10, 2026
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.

2 participants