summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2014-11-21 16:20:42 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2014-11-21 16:27:41 +1000
commit96493d6c26466885b26dcfe5e25d447c62740d88 (patch)
treeeafc0b1ab18681d3ed6db160f3ccb39a40cef6a5
parentbded6ac1d1f4aa93a5ecd8d681730734392aae8c (diff)
downloadlibinput-96493d6c26466885b26dcfe5e25d447c62740d88.tar.gz
evdev: fix leaking file descriptor
If zalloc fails, we need to close the fd. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--src/evdev.c7
1 files 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;
}