fix: safe iteration with removeAt/erase across codebase#1012
Open
deepin-wm wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Sorry @deepin-wm, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
Member
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. The 5-file iterator/erase safety fix is well-reasoned:
🤖 Generated with Claude Code |
dfcdbda to
45f4121
Compare
1. Replace removeAt(i--) with reverse iteration in wseat.cpp (2 places) for safe element removal during traversal 2. Replace removeAt(i--)+--i with reverse iteration in wglobal.cpp (1 place) for safe element removal during traversal 3. Add ordering constraint comment in wbufferrenderer.cpp to clarify destroySource must precede removeAt Log: Fixed iterator invalidation bugs in container traversal with concurrent element removal Influence: 1. Test touch input (multi-touch cancel and frame) for correctness after removing touch points 2. Test safeDisconnect with multiple connections to same receiver 3. Test WBufferRenderer source list destruction order fix: 修复waylib模块中迭代器与removeAt并发使用的安全问题 1. 在wseat.cpp(2处)中将removeAt(i--)改为倒序遍历,确保遍历中安全移除元素 2. 在wglobal.cpp(1处)中将removeAt(i--)+--i改为倒序遍历,确保遍历中安全移除元素 3. 在wbufferrenderer.cpp中添加顺序约束注释,说明destroySource必须在removeAt之前调用 Log: 修复了容器遍历中并发移除元素时的迭代器失效问题 Influence: 1. 测试触摸输入(多点触控取消和帧处理)在移除触摸点后的正确性 2. 测试同一接收者多连接场景下的safeDisconnect 3. 测试WBufferRenderer源列表销毁顺序
45f4121 to
a8f0f3c
Compare
wineee
approved these changes
Jun 18, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: deepin-wm, wineee 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 |
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.
Summary
Iterator/erase/remove safety fixes (P0+P1) to prevent use-after-destroy and iterator invalidation issues.
Changes
src/core/shellhandler.cpp— for+removeAt+break → indexOf+takeAt (8 places)Replaced forward-iteration patterns that called
removeAt(i)followed bybreakwith a saferindexOf+takeAtapproach. The original pattern was fragile: if thebreakwere ever removed or the loop continued, the iterator would be invalidated.waylib/src/server/kernel/wseat.cpp— removeAt(i--) → reverse iteration (2 places)In
doTouchNotifyCancelanddoTouchFrame, replaced forwardremoveAt(i--)with reverse traversal (for (int i = size - 1; i >= 0; --i)). Reverse iteration is inherently safe withremoveAtbecause removing an element only shifts indices below the current position.waylib/src/server/kernel/wglobal.cpp— removeAt(i--)+--i → reverse iterationIn
WWrapObject::safeDisconnect, replaced forward loop withremoveAt(i)+ manual--ireset with a clean reverse iteration loop. Same safety rationale as above.waylib/src/server/qtquick/private/wbufferrenderer.cpp— add ordering constraint commentAdded a comment clarifying that
destroySource(index)must be called beforem_sourceList.removeAt(index)becausedestroySourceaccessesm_sourceList[index].src/input/gestures.cpp— remove redundant deleteLater in destroyed callback (2 places)Removed
gesture->deleteLater()calls fromunregisterSwipeGestureandunregisterHoldGesture. These callbacks are connected toQObject::destroyed, which fires during object destruction — callingdeleteLater()on a being-destroyed object is redundant and potentially harmful.Testing