style: free(NULL) is perfectly valid so we can drop some checks
authorLuka Perkov <luka@openwrt.org>
Tue, 15 Oct 2013 10:44:19 +0000 (12:44 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Tue, 15 Oct 2013 11:16:32 +0000 (13:16 +0200)
Signed-off-by: Luka Perkov <luka@openwrt.org>
cli.c
delta.c
file.c
list.c
ucimap.c

diff --git a/cli.c b/cli.c
index a5b77a8..6fbbfe9 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -529,8 +529,7 @@ static int uci_batch_cmd(void)
                return 0;
 
        for (j = 0; j < i; j++) {
-               if (argv[j])
-                       free(argv[j]);
+               free(argv[j]);
        }
 
        return ret;
diff --git a/delta.c b/delta.c
index 50efc07..8a1ca77 100644 (file)
--- a/delta.c
+++ b/delta.c
@@ -282,8 +282,7 @@ __private int uci_load_delta(struct uci_context *ctx, struct uci_package *p, boo
                        UCI_THROW(ctx, UCI_ERR_IO);
                }
        }
-       if (filename)
-               free(filename);
+       free(filename);
        uci_close_stream(f);
        ctx->err = 0;
        return changes;
@@ -347,8 +346,7 @@ static void uci_filter_delta(struct uci_context *ctx, const char *name, const ch
        UCI_TRAP_RESTORE(ctx);
 
 done:
-       if (filename)
-               free(filename);
+       free(filename);
        uci_close_stream(pctx->file);
        uci_foreach_element_safe(&list, tmp, e) {
                uci_free_element(e);
@@ -392,12 +390,9 @@ int uci_revert(struct uci_context *ctx, struct uci_ptr *ptr)
        ctx->err = 0;
 
 error:
-       if (package)
-               free(package);
-       if (section)
-               free(section);
-       if (option)
-               free(option);
+       free(package);
+       free(section);
+       free(option);
        if (ctx->err)
                UCI_THROW(ctx, ctx->err);
        return 0;
@@ -483,8 +478,7 @@ int uci_save(struct uci_context *ctx, struct uci_package *p)
 
 done:
        uci_close_stream(f);
-       if (filename)
-               free(filename);
+       free(filename);
        if (ctx->err)
                UCI_THROW(ctx, ctx->err);
 
diff --git a/file.c b/file.c
index f7061df..509ed73 100644 (file)
--- a/file.c
+++ b/file.c
@@ -755,10 +755,8 @@ static void uci_file_commit(struct uci_context *ctx, struct uci_package **packag
        UCI_TRAP_RESTORE(ctx);
 
 done:
-       if (name)
-               free(name);
-       if (path)
-               free(path);
+       free(name);
+       free(path);
        uci_close_stream(f1);
        if (do_rename && rename(filename, p->path)) {
                unlink(filename);
diff --git a/list.c b/list.c
index 0ea7eda..863c48c 100644 (file)
--- a/list.c
+++ b/list.c
@@ -66,8 +66,7 @@ done:
 __private void
 uci_free_element(struct uci_element *e)
 {
-       if (e->name)
-               free(e->name);
+       free(e->name);
        if (!uci_list_empty(&e->list))
                uci_list_del(&e->list);
        free(e);
@@ -239,8 +238,7 @@ uci_free_package(struct uci_package **package)
        if(!p)
                return;
 
-       if (p->path)
-               free(p->path);
+       free(p->path);
        uci_foreach_element_safe(&p->sections, tmp, e) {
                uci_free_section(uci_to_section(e));
        }
@@ -502,8 +500,7 @@ int uci_rename(struct uci_context *ctx, struct uci_ptr *ptr)
                uci_add_delta(ctx, &p->delta, UCI_CMD_RENAME, ptr->section, ptr->option, ptr->value);
 
        n = uci_strdup(ctx, ptr->value);
-       if (e->name)
-               free(e->name);
+       free(e->name);
        e->name = n;
 
        if (e->type == UCI_TYPE_SECTION)
index 776a304..b68f1ae 100644 (file)
--- a/ucimap.c
+++ b/ucimap.c
@@ -713,10 +713,8 @@ ucimap_parse_section(struct uci_map *map, struct uci_sectionmap *sm, struct ucim
        return 0;
 
 error_mem:
-       if (sd->alloc_custom)
-               free(sd->alloc_custom);
-       if (sd->allocmap)
-               free(sd->allocmap);
+       free(sd->alloc_custom);
+       free(sd->allocmap);
        free(sd);
        return UCI_ERR_MEM;