libevdev_uinput_destroy: don't close non-open FD
authorOwen W. Taylor <otaylor@fishsoup.net>
Mon, 19 Jan 2015 21:45:49 +0000 (16:45 -0500)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 20 Jan 2015 22:48:50 +0000 (08:48 +1000)
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 <peter.hutterer@who-t.net>
libevdev/libevdev-uinput.c

index 33b53170f7fe3dd3fb3f5c21cb6b50d369c91af0..d115b533562bb55d8ca3fb2dc53ec4d99fb108ab 100644 (file)
@@ -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);