Git development
 help / color / mirror / Atom feed
* [PATCH] remove unnecessary NULL check before free(3)
@ 2016-10-08 14:14 René Scharfe
  0 siblings, 0 replies; only message in thread
From: René Scharfe @ 2016-10-08 14:14 UTC (permalink / raw)
  To: Git List; +Cc: Paul Tan, Stefan Beller, Junio C Hamano

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>
---
 contrib/coccinelle/free.cocci | 5 +++++
 parse-options-cb.c            | 3 +--
 2 files changed, 6 insertions(+), 2 deletions(-)
 create mode 100644 contrib/coccinelle/free.cocci

diff --git a/contrib/coccinelle/free.cocci b/contrib/coccinelle/free.cocci
new file mode 100644
index 0000000..e282131
--- /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 b5d9209..b7d8f7d 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -211,8 +211,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);
 
-- 
2.10.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-10-08 14:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-08 14:14 [PATCH] remove unnecessary NULL check before free(3) René Scharfe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox