fix(keyboard-state): fix segfault on device hotplug removal #4852
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
Fixes a segfault (SIGSEGV in
libinput_device_ref) in the keyboard-state module when input devices appear or disappear in/dev/input/.Three bugs fixed:
tryAddDevice()passes the return value oflibinput_path_add_device()directly tolibinput_device_ref()without checking for NULL. On laptops, virtual input devices (power buttons, lid switch, etc.) appear and disappear; if libinput can't open one, the NULL return causes the segfault.IN_DELETEhandler erased devices from the map without callinglibinput_path_remove_device(), leaving dangling pointers in the libinput context.std::mutexto protectlibinput_devices_which was accessed from 3 threads without synchronization.Fixes #4851
Test plan
🤖 Generated with Claude Code