compositor-drm: fix leak in evdev_udev_handler()
If the sysname of the udev device did not start with "event", the function returned without unreferencing udev_device. The function is refactored to have a common exit path that unrefs udev_device. The return value semantics are not changed. Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
This commit is contained in:
committed by
Kristian Høgsberg
parent
bf639ab892
commit
d2e69c2c6f
+10
-8
@@ -1881,34 +1881,36 @@ evdev_add_devices(struct udev *udev, struct weston_seat *seat_base)
|
|||||||
static int
|
static int
|
||||||
evdev_udev_handler(int fd, uint32_t mask, void *data)
|
evdev_udev_handler(int fd, uint32_t mask, void *data)
|
||||||
{
|
{
|
||||||
struct drm_seat *master = data;
|
struct drm_seat *seat = data;
|
||||||
struct udev_device *udev_device;
|
struct udev_device *udev_device;
|
||||||
struct evdev_input_device *device, *next;
|
struct evdev_input_device *device, *next;
|
||||||
const char *action;
|
const char *action;
|
||||||
const char *devnode;
|
const char *devnode;
|
||||||
|
|
||||||
udev_device = udev_monitor_receive_device(master->udev_monitor);
|
udev_device = udev_monitor_receive_device(seat->udev_monitor);
|
||||||
if (!udev_device)
|
if (!udev_device)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
action = udev_device_get_action(udev_device);
|
action = udev_device_get_action(udev_device);
|
||||||
if (action) {
|
if (!action)
|
||||||
|
goto out;
|
||||||
|
|
||||||
if (strncmp("event", udev_device_get_sysname(udev_device), 5) != 0)
|
if (strncmp("event", udev_device_get_sysname(udev_device), 5) != 0)
|
||||||
return 0;
|
goto out;
|
||||||
|
|
||||||
if (!strcmp(action, "add")) {
|
if (!strcmp(action, "add")) {
|
||||||
device_added(udev_device, master);
|
device_added(udev_device, seat);
|
||||||
}
|
}
|
||||||
else if (!strcmp(action, "remove")) {
|
else if (!strcmp(action, "remove")) {
|
||||||
devnode = udev_device_get_devnode(udev_device);
|
devnode = udev_device_get_devnode(udev_device);
|
||||||
wl_list_for_each_safe(device, next,
|
wl_list_for_each_safe(device, next, &seat->devices_list, link)
|
||||||
&master->devices_list, link)
|
|
||||||
if (!strcmp(device->devnode, devnode)) {
|
if (!strcmp(device->devnode, devnode)) {
|
||||||
evdev_input_device_destroy(device);
|
evdev_input_device_destroy(device);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
out:
|
||||||
udev_device_unref(udev_device);
|
udev_device_unref(udev_device);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user