system-linux: fix a glob related memleak
authorFelix Fietkau <nbd@openwrt.org>
Fri, 24 Oct 2014 12:44:34 +0000 (14:44 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Fri, 24 Oct 2014 12:44:34 +0000 (14:44 +0200)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
system-linux.c

index 7ae9e27c92f16d96776f1af2bcd2f94452d3acdf..057bc39ee0cfcf86a3b29fedeb73779eb8d1eaa8 100644 (file)
@@ -443,17 +443,18 @@ static bool system_is_bridge(const char *name, char *buf, int buflen)
 static char *system_get_bridge(const char *name, char *buf, int buflen)
 {
        char *path;
-       ssize_t len;
+       ssize_t len = -1;
        glob_t gl;
 
        snprintf(buf, buflen, "/sys/devices/virtual/net/*/brif/%s/bridge", name);
        if (glob(buf, GLOB_NOSORT, NULL, &gl) < 0)
                return NULL;
 
-       if (gl.gl_pathc == 0)
-               return NULL;
+       if (gl.gl_pathc > 0)
+               len = readlink(gl.gl_pathv[0], buf, buflen);
+
+       globfree(&gl);
 
-       len = readlink(gl.gl_pathv[0], buf, buflen);
        if (len < 0)
                return NULL;