From 8cb076d0a402f32db093f26a007d60fea1fefb15 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Sat, 19 Sep 2020 14:54:59 +0200 Subject: seat: Plug leak of deactivated fds Only if a device had an fd and was active would an fd be closed. As devices are deactivated early on session switch, this lead to fd leakage. Close fds regardless of active state. --- seatd/seat.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'seatd') diff --git a/seatd/seat.c b/seatd/seat.c index f95cbf7..9f3d882 100644 --- a/seatd/seat.c +++ b/seatd/seat.c @@ -309,30 +309,29 @@ int seat_close_device(struct client *client, struct seat_device *seat_device) { seat_device->ref_cnt--; if (seat_device->ref_cnt > 0) { - // We still have more references to this device, so leave it be. return 0; } - // The ref count hit zero, so destroy the device linked_list_remove(&seat_device->link); - if (seat_device->active && seat_device->fd != -1) { - switch (seat_device->type) { - case SEAT_DEVICE_TYPE_DRM: - if (drm_drop_master(seat_device->fd) == -1) { - log_debugf("drm_drop_master failed: %s", strerror(errno)); + if (seat_device->fd != -1) { + if (seat_device->active) { + switch (seat_device->type) { + case SEAT_DEVICE_TYPE_DRM: + if (drm_drop_master(seat_device->fd) == -1) { + log_debugf("drm_drop_master failed: %s", strerror(errno)); + } + break; + case SEAT_DEVICE_TYPE_EVDEV: + if (evdev_revoke(seat_device->fd) == -1) { + log_debugf("evdev_revoke failed: %s", strerror(errno)); + } + break; + default: + log_error("invalid seat device type"); + abort(); } - break; - case SEAT_DEVICE_TYPE_EVDEV: - if (evdev_revoke(seat_device->fd) == -1) { - log_debugf("evdev_revoke failed: %s", strerror(errno)); - } - break; - default: - log_error("invalid seat device type"); - abort(); } close(seat_device->fd); - seat_device->fd = -1; } free(seat_device->path); free(seat_device); -- cgit v1.2.3