From 27b9699fadb134e902bf65c85a82d20a9dbba31f Mon Sep 17 00:00:00 2001 From: xiepengfei Date: Fri, 18 Sep 2026 19:50:57 +0800 Subject: [PATCH] fix: fix memory leak in moveText when from equals to MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Root cause: TextEdit::moveText() missing else branch for from == to, heap-allocated UndoList, DragInsertTextUndoCommand and DeleteBackCommand objects never get freed 2. Fix: add else branch to delete list, insertCommand and delCommand (if non-null) when from == to, no behavior change for other paths 3. Impact: only affects drag-drop text to same position scenario, no regression risk for normal move operations Influence: 1. Test drag selected text to the same position (from == to) 2. Test drag text forward (from < to) with undo 3. Test drag text backward (from > to) with undo fix: 修复moveText函数from等于to时的内存泄漏 1. 根因:TextEdit::moveText() 缺少 from == to 的 else 分支, 堆分配的 UndoList、DragInsertTextUndoCommand 和 DeleteBackCommand 对象未被释放导致内存泄漏 2. 方案:添加 else 分支,在 from == to 时释放 list、 insertCommand 及 delCommand(非空时),不影响其他路径 3. 影响:仅影响拖拽文本到原位置的场景,对正常移动操作无回归风险 Influence: 1. 测试拖拽选中文本到原位置(from == to) 2. 测试向前拖拽文本(from < to)并撤销 3. 测试向后拖拽文本(from > to)并撤销 PMS: BUG-185 --- src/editor/dtextedit.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/editor/dtextedit.cpp b/src/editor/dtextedit.cpp index 545865df..b68497b7 100644 --- a/src/editor/dtextedit.cpp +++ b/src/editor/dtextedit.cpp @@ -3832,6 +3832,12 @@ void TextEdit::moveText(int from, int to, const QString &text, bool copy) } list->appendCom(insertCommand); m_pUndoStack->push(list); + } else { + delete list; + delete insertCommand; + if (delCommand) { + delete delCommand; + } } qDebug() << "Moving text completed"; }