From b97d003033bc4a1151b1f6da70823206f1bcc65a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Sat, 8 Feb 2020 04:31:51 -0800 Subject: [PATCH] Add semantic patch to NULL the destroyed pointer early Our destroy functions usually look like this: void foo_destroy(foo_t **foop) { foo_t foo = *foop; ...destroy the contents of foo... *foop = NULL; } nulling the pointer should be done as soon as possible which is not always the case. This commit adds simple semantic patch that changes the example function to: void foo_destroy(foo_t **foop) { foo_t foo = *foop; *foop = NULL; ...destroy the contents of foo... } --- cocci/null-the-pointer-early.spatch | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 cocci/null-the-pointer-early.spatch diff --git a/cocci/null-the-pointer-early.spatch b/cocci/null-the-pointer-early.spatch new file mode 100644 index 0000000000..46fdffc123 --- /dev/null +++ b/cocci/null-the-pointer-early.spatch @@ -0,0 +1,21 @@ +@@ +type T; +T **PP; +T *P; +@@ + + P = *PP; ++ *PP = NULL; + ... +- *PP = NULL; + +@@ +type T; +identifier PP; +identifier P; +@@ + + T *P = *PP; ++ *PP = NULL; + ... +- *PP = NULL;