diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2014-02-27 11:29:19 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2014-02-27 13:22:50 +1000 |
commit | fdf737494ed940d68ce68c52ee029417bb68c8ff (patch) | |
tree | 04f257ba6349dbda5c716da73ef0d6b894c8852f | |
parent | f162f00f1db2cd0141958a4d8ed4a665bfc888e3 (diff) | |
download | libevdev-fdf737494ed940d68ce68c52ee029417bb68c8ff.tar.gz |
Fix memory leaks when failing to create a uinput device
For an invalid fd, or a failure to open the device, the pre-allocated uinput
device struct would leak.
We can drop the open_uinput() function now, since skipping to the error
handling means we'll return -errno anyway.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | libevdev/libevdev-uinput.c | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/libevdev/libevdev-uinput.c b/libevdev/libevdev-uinput.c index ea9cf78..09b7044 100644 --- a/libevdev/libevdev-uinput.c +++ b/libevdev/libevdev-uinput.c @@ -155,16 +155,6 @@ set_props(const struct libevdev *dev, int fd, struct uinput_user_dev *uidev) return rc; } -static int -open_uinput(void) -{ - int fd = open("/dev/uinput", O_RDWR|O_CLOEXEC); - if (fd < 0) - return -errno; - - return fd; -} - LIBEVDEV_EXPORT int libevdev_uinput_get_fd(const struct libevdev_uinput *uinput_dev) { @@ -277,14 +267,15 @@ libevdev_uinput_create_from_device(const struct libevdev *dev, int fd, struct li return -ENOMEM; if (fd == LIBEVDEV_UINPUT_OPEN_MANAGED) { - fd = open_uinput(); + fd = open("/dev/uinput", O_RDWR|O_CLOEXEC); if (fd < 0) - return fd; + goto error; new_device->fd_is_managed = 1; } else if (fd < 0) { log_bug("Invalid fd %d\n", fd); - return -EBADF; + errno = EBADF; + goto error; } memset(&uidev, 0, sizeof(uidev)); |