Skip to content

Commit 39ea59a

Browse files
rscharfegitster
authored andcommitted
remove unnecessary NULL check before free(3)
free(3) handles NULL pointers just fine. Add a semantic patch for removing unnecessary NULL checks before calling this function, and apply it on the code base. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 353d84c commit 39ea59a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

contrib/coccinelle/free.cocci

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@@
2+
expression E;
3+
@@
4+
- if (E)
5+
free(E);

parse-options-cb.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ int parse_opt_passthru(const struct option *opt, const char *arg, int unset)
199199
if (recreate_opt(&sb, opt, arg, unset) < 0)
200200
return -1;
201201

202-
if (*opt_value)
203-
free(*opt_value);
202+
free(*opt_value);
204203

205204
*opt_value = strbuf_detach(&sb, NULL);
206205

0 commit comments

Comments
 (0)