Fix memory leaks found by using valgrind on test cases.
authorYousong Zhou <yszhou4tech@gmail.com>
Tue, 16 Dec 2014 07:00:04 +0000 (15:00 +0800)
committerFelix Fietkau <nbd@openwrt.org>
Thu, 18 Dec 2014 11:38:15 +0000 (12:38 +0100)
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
cli.c
list.c

diff --git a/cli.c b/cli.c
index 6fbbfe983fb1d1083d8bda8137843a012049e54b..55111143f78bfb1bc43b3284803783bb339ac6d8 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -360,6 +360,7 @@ static int uci_do_package_cmd(int cmd, int argc, char **argv)
 {
        char **configs = NULL;
        char **p;
+       int ret = 1;
 
        if (argc > 2)
                return 255;
@@ -369,14 +370,17 @@ static int uci_do_package_cmd(int cmd, int argc, char **argv)
 
        if ((uci_list_configs(ctx, &configs) != UCI_OK) || !configs) {
                cli_perror();
-               return 1;
+               goto out;
        }
 
        for (p = configs; *p; p++) {
                package_cmd(cmd, *p);
        }
 
-       return 0;
+       ret = 0;
+out:
+       free(configs);
+       return ret;
 }
 
 static int uci_do_add(int argc, char **argv)
diff --git a/list.c b/list.c
index faf4494ea512bafd4018eff824a6cdb3f5eca1a4..0d00f81b424bc6985360c4c3528b6f2781ee8051 100644 (file)
--- a/list.c
+++ b/list.c
@@ -346,7 +346,7 @@ uci_lookup_ext_section(struct uci_context *ctx, struct uci_ptr *ptr)
        goto done;
 
 error:
-       e = NULL;
+       free(section);
        memset(ptr, 0, sizeof(struct uci_ptr));
        UCI_THROW(ctx, UCI_ERR_INVAL);
 done: