fix: prevent crash from dangling ptr and null seatClient#1017
Draft
deepin-wm wants to merge 1 commit into
Draft
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR fixes two crash scenarios by cleaning up foreign toplevel surfaces when their wrappers are destroyed and by adding defensive null checks around seat client lookups during input capability handling. Sequence diagram for SurfaceWrapper destruction cleanup in foreign toplevel managersequenceDiagram
participant ShellHandler
participant SurfaceWrapper
participant TreelandForeignToplevel
ShellHandler->>ShellHandler: registerSurfaceToForeignToplevel(wrapper)
ShellHandler->>TreelandForeignToplevel: addSurface(wrapper)
ShellHandler->>SurfaceWrapper: connect(QObject::destroyed, lambda)
SurfaceWrapper-->>SurfaceWrapper: QObject::destroyed
SurfaceWrapper-->>ShellHandler: destroyed signal
ShellHandler->>TreelandForeignToplevel: removeSurface(wrapper)
Sequence diagram for seatClient null handling in capability broadcastsequenceDiagram
participant InputManager as TreelandInputManagerInterfaceV1
participant Helper
participant Seat
participant SeatHandle
participant SeatClient as wlr_seat_client
InputManager->>Helper: instance()
Helper-->>InputManager: helper
InputManager->>Seat: seat()
Seat-->>InputManager: seat
InputManager->>SeatHandle: handle()
SeatHandle-->>InputManager: handle
InputManager->>SeatHandle: client_for_wl_client(wl_client)
SeatHandle-->>InputManager: seatClient
alt [seatClient exists]
InputManager->>SeatClient: iterate resources
InputManager->>SeatClient: send_capability_available(handle, types, clientResource)
else [seatClient is null]
InputManager-->>InputManager: return or continue without sending
end
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
ShellHandler::registerSurfaceToForeignToplevel, consider connecting to thedestroyed(QObject*)signal and using the passedQObject*(casted if needed) instead of capturingwrapperin the lambda, to avoid relying on a pointer to an object that is in the process of being destroyed. - The repeated pattern of
client_for_wl_clientlookup plus null-check forseatClientacrossbind_resource,sendCapabilityAvailable,sendCapabilityUnavailable,onInputAdded, andonInputRemovedcould be factored into a small helper to reduce duplication and keep the flow in those functions clearer.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `ShellHandler::registerSurfaceToForeignToplevel`, consider connecting to the `destroyed(QObject*)` signal and using the passed `QObject*` (casted if needed) instead of capturing `wrapper` in the lambda, to avoid relying on a pointer to an object that is in the process of being destroyed.
- The repeated pattern of `client_for_wl_client` lookup plus null-check for `seatClient` across `bind_resource`, `sendCapabilityAvailable`, `sendCapabilityUnavailable`, `onInputAdded`, and `onInputRemoved` could be factored into a small helper to reduce duplication and keep the flow in those functions clearer.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: deepin-wm 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 |
1. Add SurfaceWrapper::aboutToBeInvalidated connection in registerSurfaceToForeignToplevel to call removeSurface when a registered SurfaceWrapper is about to be invalidated 2. Fix dangling pointer in ForeignToplevelManagerInterfaceV1::m_surfaces caused by missing removeSurface call during surface destruction 3. Add null pointer checks for seatClient in 5 locations within InputManagerInterfaceV1 to prevent crash when client disconnects Log: Fixed crash when hot-plugging screens during control center operation Influence: 1. Test hot-plugging external screens while control center is opening 2. Verify no crash when disconnecting clients during capability broadcast 3. Test system stability during rapid screen plug/unplug cycles 4. Verify ForeignToplevel surfaces are properly cleaned up on removal 5. Test input device hot-plug with multiple Wayland clients connected fix: 修复悬空指针和seatClient空指针导致的崩溃 1. 在registerSurfaceToForeignToplevel中添加SurfaceWrapper::aboutToBeInvalidated连接 在SurfaceWrapper即将失效时调用removeSurface 2. 修复ForeignToplevelManagerInterfaceV1::m_surfaces中因缺失 removeSurface调用导致的悬空指针问题 3. 在InputManagerInterfaceV1的5处位置添加seatClient空指针检查 防止客户端断开时崩溃 Log: 修复双屏热插拔时控制中心崩溃的问题 Influence: 1. 测试打开控制中心时热插拔扩展屏是否正常 2. 验证客户端断开连接时能力广播不会崩溃 3. 测试快速拔插屏幕时系统稳定性 4. 验证ForeignToplevel表面移除时正确清理 5. 测试多个Wayland客户端连接时输入设备热插拔 Fixes: linuxdeepin#183
fb935f4 to
4a8f6c2
Compare
|
TAG Bot New tag: 0.8.12 |
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
Fix crash when hot-plugging screens during control center operation.
Changes
shellhandler.cpp: Add
QObject::destroyedconnection inregisterSurfaceToForeignToplevelto callremoveSurfacewhen a registered SurfaceWrapper is destroyed. This fixes a dangling pointer inForeignToplevelManagerInterfaceV1::m_surfacescaused by missingremoveSurfacecall during surface destruction.inputmanagerinterfacev1.cpp: Add null pointer checks for
seatClientin 5 locations (bind_resource,sendCapabilityAvailable,sendCapabilityUnavailable,onInputAdded,onInputRemoved) to prevent crash when client disconnects during capability broadcast.Related Issue
Fixes #183
Summary by Sourcery
Prevent crashes during control center operation by cleaning up destroyed foreign toplevel surfaces and guarding against null seat clients when broadcasting input capabilities.
Bug Fixes: