Browse Source

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 <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
René Scharfe 8 years ago committed by Junio C Hamano
parent
commit
39ea59a257
  1. 5
      contrib/coccinelle/free.cocci
  2. 3
      parse-options-cb.c

5
contrib/coccinelle/free.cocci

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
@@
expression E;
@@
- if (E)
free(E);

3
parse-options-cb.c

@ -199,8 +199,7 @@ int parse_opt_passthru(const struct option *opt, const char *arg, int unset) @@ -199,8 +199,7 @@ int parse_opt_passthru(const struct option *opt, const char *arg, int unset)
if (recreate_opt(&sb, opt, arg, unset) < 0)
return -1;

if (*opt_value)
free(*opt_value);
free(*opt_value);

*opt_value = strbuf_detach(&sb, NULL);


Loading…
Cancel
Save