diff options
author | Andrea Canciani <ranma42@gmail.com> | 2011-08-06 08:32:30 +0200 |
---|---|---|
committer | Andrea Canciani <ranma42@gmail.com> | 2011-08-06 08:32:30 +0200 |
commit | 43623b9ccf588b3a0a76ec6450c20cc7dbef1974 (patch) | |
tree | 2d9a2393dc94f1a3f40cc0c95f9c6e1cb7e44a58 | |
parent | 3ce65b423b71ce6ede64c9cc7f6f602697a151e8 (diff) |
cocci: Add script to remove unneeded checks for NULL
NULL can be safely free()'d, but often code checks if a pointer is
non-NULL before free()'ing it. These checks can be automatically
detected and removed.
-rw-r--r-- | cleanup-free-NULL.cocci | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/cleanup-free-NULL.cocci b/cleanup-free-NULL.cocci new file mode 100644 index 0000000..e22dab7 --- /dev/null +++ b/cleanup-free-NULL.cocci @@ -0,0 +1,26 @@ +// Remove useless checks for NULL before freeing +// +// free (NULL) is a no-op, so there is no need to avoid it + +@@ +expression E; +@@ ++ free (E); ++ E = NULL; +- if (unlikely (E != NULL)) { +- free(E); +( +- E = NULL; +| +- E = 0; +) + ... +- } + +@@ +expression E; +@@ ++ free (E); +- if (unlikely (E != NULL)) { +- free (E); +- } |