[systemd-devel] [PATCH] libudev: fix memleak when enumerating childs
David Herrmann
dh.herrmann at gmail.com
Wed Sep 4 03:36:19 PDT 2013
We need to free udev-devices again if they don't match. Funny that no-one
noticed it yet since valgrind is quite verbose about it.
Fix it and free non-matching devices.
---
src/libudev/libudev-enumerate.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c
index 7065719..77f75bf 100644
--- a/src/libudev/libudev-enumerate.c
+++ b/src/libudev/libudev-enumerate.c
@@ -828,23 +828,27 @@ nomatch:
static int parent_add_child(struct udev_enumerate *enumerate, const char *path)
{
struct udev_device *dev;
+ int r = 0;
dev = udev_device_new_from_syspath(enumerate->udev, path);
if (dev == NULL)
return -ENODEV;
if (!match_subsystem(enumerate, udev_device_get_subsystem(dev)))
- return 0;
+ goto nomatch;
if (!match_sysname(enumerate, udev_device_get_sysname(dev)))
- return 0;
+ goto nomatch;
if (!match_property(enumerate, dev))
- return 0;
+ goto nomatch;
if (!match_sysattr(enumerate, dev))
- return 0;
+ goto nomatch;
syspath_add(enumerate, udev_device_get_syspath(dev));
+ r = 1;
+
+nomatch:
udev_device_unref(dev);
- return 1;
+ return r;
}
static int parent_crawl_children(struct udev_enumerate *enumerate, const char *path, int maxdepth)
--
1.8.4
More information about the systemd-devel
mailing list