Junio C Hamano <gitster@xxxxxxxxx> writes: > It is a bit sad that > > - if (E) > FREE_AND_NULL(E); > > is not sufficient to catch it. Shouldn't we be doing the same for > regular free(E) as well? IOW, like the attached patch. > ... And revised even more to also spell "E" as "E != NULL" (and "!E" as "E == NULL"), which seems to make a difference, which is even more sad. I do not want to wonder if I have to also add "NULL == E" and other variants, so I'll stop here. contrib/coccinelle/free.cocci | 60 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/contrib/coccinelle/free.cocci b/contrib/coccinelle/free.cocci index 4490069df9..29ca98796f 100644 --- a/contrib/coccinelle/free.cocci +++ b/contrib/coccinelle/free.cocci @@ -16,3 +16,63 @@ expression E; - free(E); + FREE_AND_NULL(E); - E = NULL; + +@@ +expression E; +@@ +- if (E) + FREE_AND_NULL(E); + +@@ +expression E; +@@ +- if (E != NULL) + free(E); + +@@ +expression E; +@@ +- if (E == NULL) + free(E); + +@@ +expression E; +@@ +- if (E != NULL) + FREE_AND_NULL(E); + +@@ +expression E; +@@ +- if (E) { free(E); } ++ free(E); + +@@ +expression E; +@@ +- if (!E) { free(E); } ++ free(E); + +@@ +expression E; +@@ +- if (E) { FREE_AND_NULL(E); } ++ FREE_AND_NULL(E); + +@@ +expression E; +@@ +- if (E != NULL) { free(E); } ++ free(E); + +@@ +expression E; +@@ +- if (E == NULL) { free(E); } ++ free(E); + +@@ +expression E; +@@ +- if (E != NULL) { FREE_AND_NULL(E); } ++ FREE_AND_NULL(E);