mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-28 04:34:54 -04:00
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...
}
This commit is contained in:
parent
d4f7603af2
commit
b97d003033
1 changed files with 21 additions and 0 deletions
21
cocci/null-the-pointer-early.spatch
Normal file
21
cocci/null-the-pointer-early.spatch
Normal file
|
|
@ -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;
|
||||
Loading…
Reference in a new issue