diff options
author | Felix Fietkau <nbd@openwrt.org> | 2014-10-24 14:44:34 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2014-10-24 14:44:34 +0200 |
commit | 9af0e57ce2c76db2ce49ea9fbfb5766da6000ec6 (patch) | |
tree | 275d686b4be4a8504bd92ddaab8baca4d0fa36b3 | |
parent | df7cf40cf035a3ba82b364a3aab79ff1abbddfe3 (diff) |
system-linux: fix a glob related memleak
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
-rw-r--r-- | system-linux.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/system-linux.c b/system-linux.c index 7ae9e27..057bc39 100644 --- a/system-linux.c +++ b/system-linux.c @@ -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; |