[PATCH libevdev 1/3] uinput: close the managed fd on error
Peter Hutterer
peter.hutterer at who-t.net
Thu Aug 21 19:56:25 PDT 2014
Using LIBEVDEV_UINPUT_OPEN_MANAGED can leak the fd if an error occurs after
opening it.
Found by Coverity.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
libevdev/libevdev-uinput.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libevdev/libevdev-uinput.c b/libevdev/libevdev-uinput.c
index c1b20e0..ea2b025 100644
--- a/libevdev/libevdev-uinput.c
+++ b/libevdev/libevdev-uinput.c
@@ -279,6 +279,7 @@ libevdev_uinput_create_from_device(const struct libevdev *dev, int fd, struct li
int rc;
struct uinput_user_dev uidev;
struct libevdev_uinput *new_device;
+ int close_fd_on_error = (fd == LIBEVDEV_UINPUT_OPEN_MANAGED);
new_device = alloc_uinput_device(libevdev_get_name(dev));
if (!new_device)
@@ -346,6 +347,8 @@ libevdev_uinput_create_from_device(const struct libevdev *dev, int fd, struct li
error:
rc = -errno;
libevdev_uinput_destroy(new_device);
+ if (fd != -1 && close_fd_on_error)
+ close(fd);
return rc;
}
--
1.9.3
More information about the Input-tools
mailing list