remove unnecessary NULL check before free(3)
authorRené Scharfe <l.s.r@web.de>
Sat, 8 Oct 2016 14:14:57 +0000 (16:14 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Oct 2016 18:37:41 +0000 (11:37 -0700)
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>
contrib/coccinelle/free.cocci [new file with mode: 0644]
parse-options-cb.c
diff --git a/contrib/coccinelle/free.cocci b/contrib/coccinelle/free.cocci
new file mode 100644 (file)
index 0000000..e282131
--- /dev/null
@@ -0,0 +1,5 @@
+@@
+expression E;
+@@
+- if (E)
+  free(E);
index 9667bc75a08e8b64290f5f44c92b0bac35d1d0fa..16818830e97e099286f3aa259378de1b8e9fc322 100644 (file)
@@ -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);