From 867a237c5597ab14daff50253d5d73bcc8a44ef6 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Mon, 19 Jan 2015 16:45:49 -0500 Subject: [PATCH] libevdev_uinput_destroy: don't close non-open FD The returned errno from libevdev_input_create_from_device was returned incorrectly because libevdev_uinput_destroy() would try to close the unset value of ->fd, overwriting errno. That was fixed in debe9b030c8069cdf78307888ef3b65830b25122, this patch avoids the ioctl/close calls if the fd isn't set. Signed-off-by: Peter Hutterer --- libevdev/libevdev-uinput.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libevdev/libevdev-uinput.c b/libevdev/libevdev-uinput.c index 33b5317..d115b53 100644 --- a/libevdev/libevdev-uinput.c +++ b/libevdev/libevdev-uinput.c @@ -358,9 +358,11 @@ libevdev_uinput_destroy(struct libevdev_uinput *uinput_dev) if (!uinput_dev) return; - (void)ioctl(uinput_dev->fd, UI_DEV_DESTROY, NULL); - if (uinput_dev->fd_is_managed) - close(uinput_dev->fd); + if (uinput_dev->fd >= 0) { + (void)ioctl(uinput_dev->fd, UI_DEV_DESTROY, NULL); + if (uinput_dev->fd_is_managed) + close(uinput_dev->fd); + } free(uinput_dev->syspath); free(uinput_dev->devnode); free(uinput_dev->name); -- 2.34.1