2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 10:10:06 +00: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:
Ondřej Surý 2020-02-08 04:31:51 -08:00
parent d4f7603af2
commit b97d003033

View 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;