mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2026-05-09 04:48:03 +02: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;
|
int rc;
|
||||||
struct uinput_user_dev uidev;
|
struct uinput_user_dev uidev;
|
||||||
struct libevdev_uinput *new_device;
|
struct libevdev_uinput *new_device;
|
||||||
|
int close_fd_on_error = (fd == LIBEVDEV_UINPUT_OPEN_MANAGED);
|
||||||
|
|
||||||
new_device = alloc_uinput_device(libevdev_get_name(dev));
|
new_device = alloc_uinput_device(libevdev_get_name(dev));
|
||||||
if (!new_device)
|
if (!new_device)
|
||||||
|
|
@ -346,6 +347,8 @@ libevdev_uinput_create_from_device(const struct libevdev *dev, int fd, struct li
|
||||||
error:
|
error:
|
||||||
rc = -errno;
|
rc = -errno;
|
||||||
libevdev_uinput_destroy(new_device);
|
libevdev_uinput_destroy(new_device);
|
||||||
|
if (fd != -1 && close_fd_on_error)
|
||||||
|
close(fd);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue