From: René Scharfe Date: Sat, 8 Oct 2016 14:14:57 +0000 (+0200) Subject: remove unnecessary NULL check before free(3) X-Git-Tag: v2.10.2~3^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=39ea59a2570;p=thirdparty%2Fgit.git 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 Signed-off-by: Junio C Hamano --- diff --git a/contrib/coccinelle/free.cocci b/contrib/coccinelle/free.cocci new file mode 100644 index 0000000000..e28213161a --- /dev/null +++ b/contrib/coccinelle/free.cocci @@ -0,0 +1,5 @@ +@@ +expression E; +@@ +- if (E) + free(E); diff --git a/parse-options-cb.c b/parse-options-cb.c index 9667bc75a0..16818830e9 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -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);