{"thread":{"id":"44253","subject":"[PATCH] remove unnecessary NULL check before free(3)","startedAt":"2016-10-08T14:15:53Z","lastAt":"2016-10-08T14:15:53Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"303646","messageId":"0528736a-d47a-df2f-fa91-8161075be487@web.de","threadId":"44253","inReplyTo":null,"subject":"[PATCH] remove unnecessary NULL check before free(3)","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2016-10-08T14:14:57Z","receivedAt":"2016-10-08T14:15:53Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"free(3) handles NULL pointers just fine.  Add a semantic patch for\nremoving unnecessary NULL checks before calling this function, and\napply it on the code base.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n contrib/coccinelle/free.cocci | 5 +++++\n parse-options-cb.c            | 3 +--\n 2 files changed, 6 insertions(+), 2 deletions(-)\n create mode 100644 contrib/coccinelle/free.cocci\n\ndiff --git a/contrib/coccinelle/free.cocci b/contrib/coccinelle/free.cocci\nnew file mode 100644\nindex 0000000..e282131\n--- /dev/null\n+++ b/contrib/coccinelle/free.cocci\n@@ -0,0 +1,5 @@\n+@@\n+expression E;\n+@@\n+- if (E)\n+  free(E);\ndiff --git a/parse-options-cb.c b/parse-options-cb.c\nindex b5d9209..b7d8f7d 100644\n--- a/parse-options-cb.c\n+++ b/parse-options-cb.c\n@@ -211,8 +211,7 @@ int parse_opt_passthru(const struct option *opt, const char *arg, int unset)\n \tif (recreate_opt(&sb, opt, arg, unset) < 0)\n \t\treturn -1;\n \n-\tif (*opt_value)\n-\t\tfree(*opt_value);\n+\tfree(*opt_value);\n \n \t*opt_value = strbuf_detach(&sb, NULL);\n \n-- \n2.10.0\n\n"}]}