From: Ondřej Surý Date: Sat, 8 Feb 2020 12:31:51 +0000 (-0800) Subject: Add semantic patch to NULL the destroyed pointer early X-Git-Tag: v9.16.0~12^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b97d003033bc4a1151b1f6da70823206f1bcc65a;p=thirdparty%2Fbind9.git 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... } --- diff --git a/cocci/null-the-pointer-early.spatch b/cocci/null-the-pointer-early.spatch new file mode 100644 index 00000000000..46fdffc1230 --- /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;