[PATCH libevdev 3/4] Plug a memory leak for name, uniq, phys

Peter Hutterer peter.hutterer at who-t.net
Wed Feb 26 19:25:53 PST 2014


If a device is assigned a name, uniq and/or phys before calling
libevdev_set_fd(), those values would leak.

Change the default alloc to calloc, so name, uniq, and phys are initialized to
zero before we call libevdev_reset

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 libevdev/libevdev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c
index 526c448..6127e64 100644
--- a/libevdev/libevdev.c
+++ b/libevdev/libevdev.c
@@ -133,6 +133,9 @@ log_msg(enum libevdev_log_priority priority,
 static void
 libevdev_reset(struct libevdev *dev)
 {
+	free(dev->name);
+	free(dev->phys);
+	free(dev->uniq);
 	memset(dev, 0, sizeof(*dev));
 	dev->fd = -1;
 	dev->initialized = false;
@@ -148,7 +151,7 @@ libevdev_new(void)
 {
 	struct libevdev *dev;
 
-	dev = malloc(sizeof(*dev));
+	dev = calloc(1, sizeof(*dev));
 	if (!dev)
 		return NULL;
 
-- 
1.8.4.2



More information about the Input-tools mailing list