Browse Source

style: free(NULL) is perfectly valid so we can drop some checks

Signed-off-by: Luka Perkov <luka@openwrt.org>
Luka Perkov 10 years ago
parent
commit
87be3798a9
5 changed files with 14 additions and 28 deletions
  1. 1 2
      cli.c
  2. 6 12
      delta.c
  3. 2 4
      file.c
  4. 3 6
      list.c
  5. 2 4
      ucimap.c

+ 1 - 2
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;

+ 6 - 12
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);
 

+ 2 - 4
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);

+ 3 - 6
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)

+ 2 - 4
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;