From 96493d6c26466885b26dcfe5e25d447c62740d88 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 21 Nov 2014 16:20:42 +1000 Subject: [PATCH] evdev: fix leaking file descriptor If zalloc fails, we need to close the fd. Signed-off-by: Peter Hutterer --- src/evdev.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/evdev.c b/src/evdev.c index bd742a6b..fed66cb6 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -1462,7 +1462,7 @@ evdev_device_create(struct libinput_seat *seat, const char *syspath) { struct libinput *libinput = seat->libinput; - struct evdev_device *device; + struct evdev_device *device = NULL; int rc; int fd; int unhandled_device = 0; @@ -1480,7 +1480,7 @@ evdev_device_create(struct libinput_seat *seat, device = zalloc(sizeof *device); if (device == NULL) - return NULL; + goto err; libinput_device_init(&device->base, seat); libinput_seat_ref(seat); @@ -1543,7 +1543,8 @@ evdev_device_create(struct libinput_seat *seat, err: if (fd >= 0) close_restricted(libinput, fd); - evdev_device_destroy(device); + if (device) + evdev_device_destroy(device); return unhandled_device ? EVDEV_UNHANDLED_DEVICE : NULL; }