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...
}
--- /dev/null
+@@
+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;