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>

René Scharfe committed Oct 8, 2016 at 16:14 UTC 39ea59a2570547166834ceeff9ae0c0c05748f35
2 files changed +6 -2
contrib/coccinelle/free.cocci new
+5
@@ -0,0 +1,5 @@
1 +@@
2 +expression E;
3 +@@
4 +- if (E)
5 + free(E);
parse-options-cb.c
+1 -2
@@ -199,8 +199,7 @@ int parse_opt_passthru(const struct option *opt, const char *arg, int unset)
199 if (recreate_opt(&sb, opt, arg, unset) < 0)
200 return -1;
201
202 - if (*opt_value)
203 - free(*opt_value);
202 + free(*opt_value);
203
204 *opt_value = strbuf_detach(&sb, NULL);
205