diff options
author | Kenny Levinsen <kl@kl.wtf> | 2020-09-19 14:54:59 +0200 |
---|---|---|
committer | Kenny Levinsen <kl@kl.wtf> | 2020-09-22 01:01:46 +0200 |
commit | 8cb076d0a402f32db093f26a007d60fea1fefb15 (patch) | |
tree | de93fb1c6f84f5d14aa499c012ee46e457c6414f /seatd/seat.c | |
parent | 51c7467516d6213d1ff614e4db1e216de6367cc8 (diff) |
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.
Diffstat (limited to 'seatd/seat.c')
-rw-r--r-- | seatd/seat.c | 33 |
1 files changed, 16 insertions, 17 deletions
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); |