source3/passdb/py_passdb.c: wrap all calls in talloc_stackframe()
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 18 Jul 2012 05:37:28 +0000 (15:07 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 18 Jul 2012 05:37:28 +0000 (15:07 +0930)
commitd54ebd36cc95ae13844bd00d5bbb2e3ff1a06285
tree1ac6002dfbf93e1b0dafc414bdfac214047adc1b
parent99272331c60afa900852d996196b434ecd897287
source3/passdb/py_passdb.c: wrap all calls in talloc_stackframe()

dbwrap needs it.  Some calls were already wrapped, but they checked the
talloc_stackframe() return unnecessarily: it can never be NULL.

This is the coccinelle patch I used:

// Add in a stackframe to every function: be sure to free it on (every) return
@rule0@
identifier func;
@@
func(...) {
+TALLOC_CTX *frame = talloc_stackframe();
<...
+talloc_free(frame);
return ...;
...>
}

// Get rid of tframe allocation/frees, replace usage with frame.
@rule1@
identifier func;
identifier oldframe;
@@
func(...) {
...
-TALLOC_CTX *oldframe;
...
-if ((oldframe = talloc_stackframe()) == NULL) {
-  ...
-}
<...
-talloc_free(oldframe);
...>
}

// Get rid of tframe (variant 2)
@rule2@
identifier func;
identifier oldframe;
@@
func(...) {
...
-TALLOC_CTX *oldframe;
...
-oldframe = talloc_stackframe();
-if (oldframe == NULL) {
-  ...
-}
<...
-talloc_free(oldframe);
...>
}

// Change tframe to frame
@rule3@
identifier func;
@@
func(...) {
<...
-tframe
+frame
...>
}

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
source3/passdb/py_passdb.c