[PATCH libevdev 1/4] Plug three memory leaks in the uinput code

Peter Hutterer peter.hutterer at who-t.net
Wed Aug 14 21:12:37 PDT 2013


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
This can be squashed into the original patches, but to make the review easier,
here's a separate one.

 libevdev/libevdev-uinput.c | 6 +++++-
 test/test-common-uinput.c  | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libevdev/libevdev-uinput.c b/libevdev/libevdev-uinput.c
index 39e0f96..9fd36b4 100644
--- a/libevdev/libevdev-uinput.c
+++ b/libevdev/libevdev-uinput.c
@@ -47,8 +47,10 @@ alloc_uinput_device(const char *name)
 	struct libevdev_uinput *uinput_dev;
 
 	uinput_dev = calloc(1, sizeof(struct libevdev_uinput));
-	if (uinput_dev)
+	if (uinput_dev) {
 		uinput_dev->name = strdup(name);
+		uinput_dev->fd = -1;
+	}
 
 	return uinput_dev;
 }
@@ -190,12 +192,14 @@ libevdev_uinput_create_from_device(const struct libevdev *dev, int fd, struct li
 	return 0;
 
 error:
+	libevdev_uinput_destroy(new_device);
 	return -errno;
 }
 
 void libevdev_uinput_destroy(struct libevdev_uinput *uinput_dev)
 {
 	ioctl(uinput_dev->fd, UI_DEV_DESTROY, NULL);
+	free(uinput_dev->syspath);
 	free(uinput_dev->name);
 	free(uinput_dev);
 }
diff --git a/test/test-common-uinput.c b/test/test-common-uinput.c
index fe1bfb0..b8a5798 100644
--- a/test/test-common-uinput.c
+++ b/test/test-common-uinput.c
@@ -123,6 +123,7 @@ uinput_device_free(struct uinput_device *dev)
 	if (dev->dev_fd != -1)
 		close(dev->dev_fd);
 	libevdev_free(dev->d);
+	free(dev->devnode);
 	free(dev);
 }
 
-- 
1.8.2.1



More information about the Input-tools mailing list