diff options
| author | Simon Ser <contact@emersion.fr> | 2025-05-19 18:25:16 +0200 |
|---|---|---|
| committer | Simon Ser <contact@emersion.fr> | 2025-05-25 23:33:25 +0200 |
| commit | 0611f9684d77bce6e25fb37ad58550a516e49c47 (patch) | |
| tree | fce9a9760bf3204453c94a02c88f4cc826e46b7c | |
| parent | eca8434695fb5aed0c5691a27becc3d38191b165 (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.c | 26 |
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; } |
