From: Owen W. Taylor Date: Mon, 19 Jan 2015 21:45:49 +0000 (-0500) Subject: libevdev_uinput_destroy: don't close non-open FD X-Git-Tag: libevdev-1.4~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=867a237c5597ab14daff50253d5d73bcc8a44ef6;p=platform%2Fupstream%2Flibevdev.git 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 --- 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);