aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFurkan Sahin <furkan-dev@proton.me>2025-05-19 18:25:16 +0200
committerFurkan Sahin <furkan-dev@proton.me>2025-05-19 18:25:16 +0200
commit610e1b3318ff0efbefb01ced2f528b3cc4af77fe (patch)
tree228dab0bcacf98a58db934c0d26239a6c3d9d762
parent7462d624968bda2801e72656d2deaa67c83f8fa6 (diff)
input: fix udev_device leak
libinput_device_get_udev_device() returns a ref'ed handle: https://wayland.freedesktop.org/libinput/doc/latest/api/group__device.html#gac13c64ba19fc19094cff0e5354a2a7ce Similar to this wlroots MR: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/5074
-rw-r--r--sway/input/libinput.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/sway/input/libinput.c b/sway/input/libinput.c
index f76c6505..b98c4cc8 100644
--- a/sway/input/libinput.c
+++ b/sway/input/libinput.c
@@ -399,6 +399,19 @@ void sway_input_reset_libinput_device(struct sway_input_device *input_device) {
}
}
+static bool sway_udev_device_is_builtin(struct udev_device *udev_device) {
+ const char *id_path = udev_device_get_property_value(udev_device, "ID_PATH");
+ if (!id_path) {
+ return false;
+ }
+
+ if (has_prefix(id_path, "platform-")) {
+ return true;
+ }
+
+ return has_prefix(id_path, "pci-") && strstr(id_path, "-platform-");
+}
+
bool sway_libinput_device_is_builtin(struct sway_input_device *sway_device) {
if (!wlr_input_device_is_libinput(sway_device->wlr_device)) {
return false;
@@ -412,14 +425,7 @@ bool sway_libinput_device_is_builtin(struct sway_input_device *sway_device) {
return false;
}
- const char *id_path = udev_device_get_property_value(udev_device, "ID_PATH");
- if (!id_path) {
- return false;
- }
-
- if (has_prefix(id_path, "platform-")) {
- return true;
- }
-
- return has_prefix(id_path, "pci-") && strstr(id_path, "-platform-");
+ bool is_builtin = sway_udev_device_is_builtin(udev_device);
+ udev_device_unref(udev_device);
+ return is_builtin;
}