summaryrefslogtreecommitdiff
path: root/contrib/coccinelle/free.cocci
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-06-24 21:28:41 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-06-24 21:28:41 (GMT)
commit50f03c6676ed5ea040dd53272882d3aac2ee1b48 (patch)
tree8bf9680918762ffa077832674da9cca98c8c1888 /contrib/coccinelle/free.cocci
parentcda4ba30b1d6257524b9412ed4d7c44645fe0369 (diff)
parent88ce3ef636b1385e861ec0e9e2155248b999b032 (diff)
downloadgit-50f03c6676ed5ea040dd53272882d3aac2ee1b48.zip
git-50f03c6676ed5ea040dd53272882d3aac2ee1b48.tar.gz
git-50f03c6676ed5ea040dd53272882d3aac2ee1b48.tar.bz2
Merge branch 'ab/free-and-null'
A common pattern to free a piece of memory and assign NULL to the pointer that used to point at it has been replaced with a new FREE_AND_NULL() macro. * ab/free-and-null: *.[ch] refactoring: make use of the FREE_AND_NULL() macro coccinelle: make use of the "expression" FREE_AND_NULL() rule coccinelle: add a rule to make "expression" code use FREE_AND_NULL() coccinelle: make use of the "type" FREE_AND_NULL() rule coccinelle: add a rule to make "type" code use FREE_AND_NULL() git-compat-util: add a FREE_AND_NULL() wrapper around free(ptr); ptr = NULL
Diffstat (limited to 'contrib/coccinelle/free.cocci')
-rw-r--r--contrib/coccinelle/free.cocci15
1 files changed, 15 insertions, 0 deletions
diff --git a/contrib/coccinelle/free.cocci b/contrib/coccinelle/free.cocci
index c03ba73..f2d97e7 100644
--- a/contrib/coccinelle/free.cocci
+++ b/contrib/coccinelle/free.cocci
@@ -9,3 +9,18 @@ expression E;
@@
- if (!E)
free(E);
+
+@@
+type T;
+T *ptr;
+@@
+- free(ptr);
+- ptr = NULL;
++ FREE_AND_NULL(ptr);
+
+@@
+expression E;
+@@
+- free(E);
+- E = NULL;
++ FREE_AND_NULL(E);