handler: Fix memory leak
authorHans Dedecker <dedeckeh@gmail.com>
Mon, 1 Feb 2016 09:56:25 +0000 (10:56 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Mon, 1 Feb 2016 10:09:57 +0000 (11:09 +0100)
Call globfree to free dynamically allocated storage from a previous glob call

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
handler.c

index f81a7c581510fe6b4dd7613388cafa8dcdbbd3e3..0c4627f1ca549429c63a3e3809a47d5bf4429b7e 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -128,10 +128,14 @@ void netifd_init_script_handlers(int dir_fd, script_dump_cb cb)
        int i, prev_fd;
 
        prev_fd = netifd_dir_push(dir_fd);
-       glob("./*.sh", 0, NULL, &g);
+       if (glob("./*.sh", 0, NULL, &g))
+               return;
+
        for (i = 0; i < g.gl_pathc; i++)
                netifd_parse_script_handler(g.gl_pathv[i], cb);
        netifd_dir_pop(prev_fd);
+
+       globfree(&g);
 }
 
 char *