mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2025-12-25 01:10:10 +01:00
uinput: close the managed fd on error
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@who-t.net>
This commit is contained in:
parent
e4c315fc16
commit
53958c56cd
1 changed files with 3 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue