summaryrefslogtreecommitdiff
path: root/src/libudev
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2013-09-04 12:36:19 +0200
committerAnthony G. Basile <blueness@gentoo.org>2013-09-10 05:54:15 -0400
commit764d75735d6994d6ca89af8658d4a07c884b37cb (patch)
tree4dff8ad73d087505f4281d11a08e9b36c4fad4f6 /src/libudev
parent6790927a88fa6e4597a58bbdc08b9fdfdff2286c (diff)
libudev: fix memleak when enumerating childs
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.
Diffstat (limited to 'src/libudev')
-rw-r--r--src/libudev/libudev-enumerate.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c
index 3e791074f3..b96e5b278f 100644
--- a/src/libudev/libudev-enumerate.c
+++ b/src/libudev/libudev-enumerate.c
@@ -829,23 +829,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)