[6210] 修复删除 AI 会话时崩溃的问题 - #4694
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
通过 Chat 标签页会话列表条目右侧「…」菜单删除 AI 会话(单删或「Delete selected」多删)时,应用崩溃。
原因
「…」按钮的
clicked槽内以QMenu menu (btn)在栈上构造菜单,父对象为moreButton(itemWidget的孙控件)。用户选择「删除」后emit deleteRequested同步走完ChatController::onDeleteRequested→removePanel→removeItem→destroyItem链,而destroyItem对itemWidget执行同步delete:sidebarButton→moreButton→ 其子对象——包括栈上的QMenu,对栈地址执行delete导致堆损坏;clicked信号派发栈帧中的发送者按钮,槽返回后 use-after-free。修改
ChatSidebar::destroyItem:同步delete改为deleteLater(),与同文件removePanel既有做法一致。条目仍立即从列表移除(hide+setParent (nullptr)+items_.erase),仅内存销毁推迟到事件循环。destroyItem是侧边栏条目的唯一共享拆除路径,单删、多删及未来任何移除触发点均被覆盖。test_removeItem_from_more_menu_frame_defers_destruction:复现生产链路(以moreButton为父的栈上QMenu+ 槽内同步removeItem),断言信号派发帧返回前发送者存活、控制权回到事件循环后才真正销毁。旧实现跑此用例会因堆损坏崩溃。验证
xmake b qt_chat_tab_widget_test && xmake r qt_chat_tab_widget_test:132 通过 / 0 失败(含新增回归用例)gf fmt --changed-since=main:无遗留格式问题🤖 Generated with Claude Code