fix ref_free_steal
[metze/samba/wip.git] / lib / talloc / testsuite.c
index 3d490ddf49319139093893caff827c9fd0346bc6..8720f0dbff21d8ebfab0d0a3625a31456428757f 100644 (file)
@@ -66,8 +66,8 @@ static double timeval_elapsed(struct timeval *tv)
 
 #define CHECK_SIZE(test, ptr, tsize) do { \
        if (talloc_total_size(ptr) != (tsize)) { \
-               printf("failed: %s [\nwrong '%s' tree size: got %u  expected %u\n]\n", \
-                      test, #ptr, \
+               printf("failed: %s [\n%s: wrong '%s' tree size: got %u  expected %u\n]\n", \
+                      test, __location__, #ptr, \
                       (unsigned)talloc_total_size(ptr), \
                       (unsigned)tsize); \
                talloc_report_full(ptr, stdout); \
@@ -77,8 +77,8 @@ static double timeval_elapsed(struct timeval *tv)
 
 #define CHECK_BLOCKS(test, ptr, tblocks) do { \
        if (talloc_total_blocks(ptr) != (tblocks)) { \
-               printf("failed: %s [\nwrong '%s' tree blocks: got %u  expected %u\n]\n", \
-                      test, #ptr, \
+               printf("failed: %s [\n%s: wrong '%s' tree blocks: got %u  expected %u\n]\n", \
+                      test, __location__, #ptr, \
                       (unsigned)talloc_total_blocks(ptr), \
                       (unsigned)tblocks); \
                talloc_report_full(ptr, stdout); \
@@ -88,8 +88,8 @@ static double timeval_elapsed(struct timeval *tv)
 
 #define CHECK_PARENT(test, ptr, parent) do { \
        if (talloc_parent(ptr) != (parent)) { \
-               printf("failed: %s [\n'%s' has wrong parent: got %p  expected %p\n]\n", \
-                      test, #ptr, \
+               printf("failed: %s [\n%s: '%s' has wrong parent: got %p  expected %p\n]\n", \
+                      test, __location__, #ptr, \
                       talloc_parent(ptr), \
                       (parent)); \
                talloc_report_full(ptr, stdout); \
@@ -99,6 +99,37 @@ static double timeval_elapsed(struct timeval *tv)
        } \
 } while (0)
 
+#define CHECK_NOT_PARENT(test, ptr, parent) do { \
+       if (talloc_parent(ptr) == (parent)) { \
+               printf("failed: %s [\n%s: '%s' has wrong parent: got %p  expected a difference\n]\n", \
+                      test, __location__, #ptr, \
+                      (parent)); \
+               talloc_report_full(ptr, stdout); \
+               talloc_report_full(parent, stdout); \
+               talloc_report_full(NULL, stdout); \
+               return false; \
+       } \
+} while (0)
+
+static unsigned int test_abort_count;
+
+static void test_abort_fn(const char *reason)
+{
+       printf("# test_abort_fn(%s)\n", reason);
+       test_abort_count++;
+}
+
+static void test_abort_start(void)
+{
+       test_abort_count = 0;
+       talloc_set_abort_fn(test_abort_fn);
+}
+
+static void test_abort_stop(void)
+{
+       test_abort_count = 0;
+       talloc_set_abort_fn(NULL);
+}
 
 /*
   test references 
@@ -128,15 +159,15 @@ static bool test_ref1(void)
        talloc_free(p2);
        talloc_report_full(root, stderr);
 
-       CHECK_BLOCKS("ref1", p1, 5);
+       CHECK_BLOCKS("ref1", p1, 4);
        CHECK_BLOCKS("ref1", p2, 1);
-       CHECK_BLOCKS("ref1", r1, 1);
+       CHECK_BLOCKS("ref1", r1, 2);
 
        fprintf(stderr, "Freeing p1\n");
        talloc_free(p1);
        talloc_report_full(root, stderr);
 
-       CHECK_BLOCKS("ref1", r1, 1);
+       CHECK_BLOCKS("ref1", r1, 2);
 
        fprintf(stderr, "Freeing r1\n");
        talloc_free(r1);
@@ -180,7 +211,7 @@ static bool test_ref2(void)
        CHECK_BLOCKS("ref2", r1, 2);
 
        fprintf(stderr, "Freeing ref\n");
-       talloc_free(ref);
+       talloc_unlink(r1, ref);
        talloc_report_full(root, stderr);
 
        CHECK_BLOCKS("ref2", p1, 5);
@@ -370,12 +401,11 @@ static bool test_misc(void)
        talloc_increase_ref_count(p1);
        talloc_increase_ref_count(p1);
        talloc_increase_ref_count(p1);
-       CHECK_BLOCKS("misc", p1, 1);
-       CHECK_BLOCKS("misc", root, 2);
-       talloc_free(p1);
+       CHECK_BLOCKS("misc", NULL, 7);
        CHECK_BLOCKS("misc", p1, 1);
        CHECK_BLOCKS("misc", root, 2);
        talloc_unlink(NULL, p1);
+       CHECK_BLOCKS("misc", NULL, 6);
        CHECK_BLOCKS("misc", p1, 1);
        CHECK_BLOCKS("misc", root, 2);
        p2 = talloc_strdup(p1, "foo");
@@ -384,28 +414,38 @@ static bool test_misc(void)
        torture_assert("misc", talloc_unlink(p1, p2) == 0,
                "failed: talloc_unlink() of parent should succeed\n");
        talloc_free(p1);
+       CHECK_BLOCKS("misc", NULL, 6);
        CHECK_BLOCKS("misc", p1, 1);
-       CHECK_BLOCKS("misc", root, 2);
+       CHECK_BLOCKS("misc", root, 1);
+       talloc_unlink(NULL, p1);
+       CHECK_BLOCKS("misc", NULL, 5);
+       CHECK_BLOCKS("misc", p1, 1);
+       CHECK_BLOCKS("misc", root, 1);
 
        name = talloc_set_name(p1, "my name is %s", "foo");
        torture_assert_str_equal("misc", talloc_get_name(p1), "my name is foo",
                "failed: wrong name after talloc_set_name(my name is foo)");
+       CHECK_BLOCKS("misc", NULL, 6);
        CHECK_BLOCKS("misc", p1, 2);
-       CHECK_BLOCKS("misc", root, 3);
+       CHECK_BLOCKS("misc", root, 1);
 
        talloc_set_name_const(p1, NULL);
        torture_assert_str_equal ("misc", talloc_get_name(p1), "UNNAMED",
                "failed: wrong name after talloc_set_name(NULL)");
+       CHECK_BLOCKS("misc", NULL, 6);
        CHECK_BLOCKS("misc", p1, 2);
-       CHECK_BLOCKS("misc", root, 3);
+       CHECK_BLOCKS("misc", root, 1);
 
        torture_assert("misc", talloc_free(NULL) == -1, 
                                   "talloc_free(NULL) should give -1\n");
 
        talloc_set_destructor(p1, fail_destructor);
-       torture_assert("misc", talloc_free(p1) == -1, 
-               "Failed destructor should cause talloc_free to fail\n");
+       torture_assert("misc", talloc_unlink(NULL, p1) == -1,
+               "Failed destructor should cause talloc_unlink to fail\n");
        talloc_set_destructor(p1, NULL);
+       CHECK_BLOCKS("misc", NULL, 6);
+       CHECK_BLOCKS("misc", p1, 2);
+       CHECK_BLOCKS("misc", root, 1);
 
        talloc_report(root, stderr);
 
@@ -439,13 +479,18 @@ static bool test_misc(void)
        d = talloc_realloc(p1, d, double, 0x20000000);
        torture_assert("misc", !d, "failed: integer overflow not detected\n");
 
-       talloc_free(p1);
+       CHECK_BLOCKS("misc", NULL, 7);
+       talloc_unlink(NULL, p1);
+       CHECK_BLOCKS("misc", NULL, 3);
        CHECK_BLOCKS("misc", root, 1);
 
        p1 = talloc_named(root, 100, "%d bytes", 100);
+       CHECK_BLOCKS("misc", NULL, 5);
        CHECK_BLOCKS("misc", p1, 2);
        CHECK_BLOCKS("misc", root, 3);
        talloc_unlink(root, p1);
+       CHECK_BLOCKS("misc", NULL, 3);
+       CHECK_BLOCKS("misc", root, 1);
 
        p1 = talloc_init("%d bytes", 200);
        p2 = talloc_asprintf(p1, "my test '%s'", "string");
@@ -765,16 +810,25 @@ static bool test_unref_reparent(void)
        p2 = talloc_named_const(root, 1, "parent by reference");
 
        c1 = talloc_named_const(p1, 1, "child");
+       CHECK_BLOCKS("unref_reparent", root, 4);
+       CHECK_SIZE("unref_reparent", root, 3);
        talloc_reference(p2, c1);
+       CHECK_BLOCKS("unref_reparent", root, 5);
+       CHECK_SIZE("unref_reparent", root, 3);
 
+       CHECK_BLOCKS("unref_reparent", root, 5);
+       CHECK_SIZE("unref_reparent", root, 3);
        CHECK_PARENT("unref_reparent", c1, p1);
 
        talloc_free(p1);
 
-       CHECK_PARENT("unref_reparent", c1, p2);
+       CHECK_BLOCKS("unref_reparent", root, 3);
+       CHECK_SIZE("unref_reparent", root, 1);
+       CHECK_NOT_PARENT("unref_reparent", c1, p2);
 
        talloc_unlink(p2, c1);
 
+       CHECK_BLOCKS("unref_reparent", root, 2);
        CHECK_SIZE("unref_reparent", root, 1);
 
        talloc_free(p2);
@@ -784,6 +838,352 @@ static bool test_unref_reparent(void)
        return true;
 }
 
+/* If a referenced allocation is explicitly freed the new owner
+   should be the same as if the same allocation is implicitly freed
+   (because it's owner was freed).
+   Traditionally in talloc an explicit free will free the top non-child reference
+   but an implicit free will move the top (any) reference to be the new owner */
+static bool test_implicit_explicit_free(void)
+{
+       void *root, *p1, *p2, *p3, *ref, *r1;
+       int e, i;
+
+       printf("test: test_implicit_explicit_free\n# SINGLE REFERENCE IMPLICIT FREE\n");
+
+       root = talloc_named_const(NULL, 0, "root");
+       p1 = talloc_named_const(root, 1, "p1");
+       p2 = talloc_named_const(p1, 1, "p2");
+       /* Now root owns p1, and p1 owns p2 */
+
+       r1 = talloc_named_const(root, 1, "r1");
+       ref = talloc_reference(r1, p2);
+       /* now r1 has ref reference to p2 */
+       talloc_report_full(root, stderr);
+
+       CHECK_BLOCKS(__FUNCTION__, p1, 2);
+       CHECK_BLOCKS(__FUNCTION__, p2, 1);
+       CHECK_BLOCKS(__FUNCTION__, r1, 2);
+
+       fprintf(stderr, "Freeing p2\n");
+       talloc_free(p2);
+       /* how many blocks is r1 taking against p2 ? */
+       e=talloc_total_blocks(r1);
+
+       talloc_report_full(root, stderr);
+       talloc_free(root);
+
+       /* now repeat, but this time free p1 */
+       printf("# SINGLE REFERENCE EXPLICIT FREE\n");
+
+       root = talloc_named_const(NULL, 0, "root");
+       p1 = talloc_named_const(root, 1, "p1");
+       p2 = talloc_named_const(p1, 1, "p2");
+       /* Now root owns p1, and p1 owns p2 */
+
+       r1 = talloc_named_const(root, 1, "r1");
+       ref = talloc_reference(r1, p2);
+       /* now r1 has ref reference to p2 */
+       talloc_report_full(NULL, stderr);
+
+       CHECK_BLOCKS(__FUNCTION__, p1, 2);
+       CHECK_BLOCKS(__FUNCTION__, p2, 1);
+       CHECK_BLOCKS(__FUNCTION__, r1, 2);
+
+       fprintf(stderr, "Freeing p1\n");
+       talloc_free(p1);
+       /* how many blocks is r1 taking against p2 ? */
+       i=talloc_total_blocks(r1);
+       talloc_report_full(NULL, stderr);
+
+       CHECK_BLOCKS(__FUNCTION__,r1, e);
+
+       talloc_free(root);
+
+       printf("success: test_implicit_explicit_free\n");
+       return true;
+}
+
+/* If take r1 reference to p2 and then free p2's parent
+   p2 should still be around by virtue of the reference.
+   In current talloc r1 will be the parent
+   In proposed talloc r1 will be the reference with no parent */
+static bool test_ref_free_owner(void)
+{
+       void *root, *p1, *p2, *ref, *r1;
+
+       printf("test: ref_free_owner\n# SINGLE REFERENCE FREE OWNER FREE\n");
+
+       root = talloc_named_const(NULL, 0, "root");
+       p1 = talloc_named_const(root, 1, "p1");
+       p2 = talloc_named_const(p1, 1, "p2");
+       /* Now root owns p1 ,and p2 owns p2 */
+
+       r1 = talloc_named_const(root, 1, "r1");
+       ref = talloc_reference(r1, p2);
+       /* now r1 has ref reference to p2 */
+       talloc_report_full(root, stderr);
+
+       CHECK_BLOCKS(__FUNCTION__, NULL, 7);
+       CHECK_BLOCKS(__FUNCTION__, p1, 2);
+       CHECK_BLOCKS(__FUNCTION__, p2, 1);
+       CHECK_BLOCKS(__FUNCTION__, r1, 2);
+
+       fprintf(stderr, "Freeing p1\n");
+       talloc_free(p1);
+       /* r1 should have ref reference to p2 still */
+       talloc_report_full(NULL, stderr);
+       CHECK_BLOCKS(__FUNCTION__, NULL, 6);
+       CHECK_BLOCKS(__FUNCTION__, r1, 2);
+       CHECK_BLOCKS(__FUNCTION__, p2, 1);
+
+       /* if we free r1 then p2 should vanish */
+       fprintf(stderr, "Freeing r1\n");
+       talloc_free(r1);
+
+       talloc_report_full(NULL, stderr);
+       CHECK_BLOCKS(__FUNCTION__, NULL, 3);
+       CHECK_BLOCKS(__FUNCTION__, root, 1);
+
+       talloc_free(root);
+       printf("success: ref_free_owner\n");
+       return true;
+}
+
+/* If take r1 reference to p2 and then free p2
+   p2 should still be around by virtue of the reference.
+   In current talloc r1 will be the parent
+   In proposed talloc r1 will be the reference with no parent */
+static bool test_ref_free_self(void)
+{
+       void *root, *p1, *p2, *ref, *r1;
+
+       printf("test: ref_free_self\n# SINGLE REFERENCE FREE SELF FREE\n");
+
+       root = talloc_named_const(NULL, 0, "root");
+       p1 = talloc_named_const(root, 1, "p1");
+       p2 = talloc_named_const(p1, 1, "p2");
+       /* Now root owns p1, and p1 owns p2 */
+
+       r1 = talloc_named_const(root, 1, "r1");
+       ref = talloc_reference(r1, p2);
+       /* now r1 has ref reference to p2 */
+       talloc_report_full(NULL, stderr);
+
+       CHECK_BLOCKS(__FUNCTION__, NULL, 7);
+       CHECK_BLOCKS(__FUNCTION__, p1, 2);
+       CHECK_BLOCKS(__FUNCTION__, p2, 1);
+       CHECK_BLOCKS(__FUNCTION__, r1, 2);
+
+       fprintf(stderr, "Freeing p2\n");
+       talloc_free(p2);
+       /* r1 should have ref reference to p2 still */
+       talloc_report_full(NULL, stderr);
+       CHECK_BLOCKS(__FUNCTION__, NULL, 7);
+       CHECK_BLOCKS(__FUNCTION__, p1, 1);
+       CHECK_BLOCKS(__FUNCTION__, p2, 1);
+       CHECK_BLOCKS(__FUNCTION__, r1, 2);
+
+       /* if we free r1 then p2 should also vanish */
+       fprintf(stderr, "Freeing r1\n");
+       talloc_free(r1);
+
+       fprintf(stderr, "Checking that p1 is empty and freeing p1\n");
+       CHECK_BLOCKS(__FUNCTION__, NULL, 4);
+       CHECK_BLOCKS(__FUNCTION__, p1, 1);
+       talloc_free(p1);
+
+       talloc_report_full(NULL, stderr);
+       CHECK_BLOCKS(__FUNCTION__, NULL, 3);
+       CHECK_BLOCKS(__FUNCTION__, root, 1);
+
+       talloc_free(root);
+       CHECK_BLOCKS(__FUNCTION__, NULL, 2);
+       printf("success: ref_free_self\n");
+       return true;
+}
+
+/* check that an allocation that is freed while also referenced finally goes
+   away when the reference is released */
+static bool test_ref_free(void)
+{
+       void *root, *p1, *p2, *ref, *r1;
+
+       printf("test: test_ref_free\n# FREE ON SINGLE REFERENCE FREE\n");
+
+       root = talloc_named_const(NULL, 0, "root");
+       p1 = talloc_named_const(root, 1, "p1");
+       p2 = talloc_named_const(p1, 1, "p2");
+       /* Now root owns p1, and p1 owns p2 */
+
+       r1 = talloc_named_const(root, 1, "r1");
+       ref = talloc_reference(r1, p2);
+       /* now r1 has ref reference to p2 */
+       talloc_report_full(root, stderr);
+
+       CHECK_BLOCKS(__FUNCTION__, p1, 2);
+       CHECK_BLOCKS(__FUNCTION__, p2, 1);
+       CHECK_BLOCKS(__FUNCTION__, r1, 2);
+
+       fprintf(stderr, "Freeing p2\n");
+       talloc_free(p2);
+       /* r1 should have ref reference to p2 still */
+       talloc_report_full(root, stderr);
+
+       CHECK_BLOCKS(__FUNCTION__, p1, 1);
+       CHECK_BLOCKS(__FUNCTION__, root, 4);
+       CHECK_BLOCKS(__FUNCTION__, r1, 2);
+
+       /* if we free r1 then p2 should also vanish */
+       fprintf(stderr, "Freeing r1\n");
+       talloc_free(r1);
+       /* p2 should have gone away  */
+       talloc_report_full(NULL, stderr);
+       CHECK_BLOCKS(__FUNCTION__, root, 2);
+       CHECK_BLOCKS(__FUNCTION__, p1, 1);
+
+       talloc_free(root);
+       printf("success: test_ref_free\n");
+       return true;
+}
+
+/* If an object having references from children that are also referenced is
+   freed, the child reference will be removed, but the child will survive
+   (because of it's reference) and the object will still be freed leaving
+   a dangling reference */
+static bool test_dangling_loop(void)
+{
+       void *root, *p1, *p2, *ref, *r1, *r2;
+
+       printf("test: %s\n# FREE ON SINGLE REFERENCE FREE\n",__FUNCTION__);
+
+       root = talloc_named_const(NULL, 0, "root");
+       p1 = talloc_named_const(root, 1, "p1");
+       p2 = talloc_named_const(p1, 1, "p2");
+       /* Now root owns p1, and p1 owns p2 */
+
+       /* someone takes a ref on p2 */
+       r1 = talloc_named_const(root, 1, "r1");
+       ref = talloc_reference(r1, p2);
+
+       /* p2 takes a ref on p1 */
+       talloc_reference(p2, p1);
+
+       talloc_report_full(NULL, stderr);
+
+       CHECK_BLOCKS(__FUNCTION__, root, 6);
+       CHECK_BLOCKS(__FUNCTION__, p1, 3);
+       CHECK_BLOCKS(__FUNCTION__, p2, 2);
+       CHECK_BLOCKS(__FUNCTION__, r1, 2);
+
+       /* talloc will wrongly spot a loop and free p2's ref, and then p1
+          leaving a dangling pointer */
+       fprintf(stderr, "Freeing p1\n");
+       talloc_free(p1);
+       /* p1 should not get freed as it is referenced from something (a child) that won't free */
+       /* r1 should have ref reference to p2 still */
+       talloc_report_full(NULL, stderr);
+
+       CHECK_BLOCKS(__FUNCTION__, root, 3);
+       /* The ugly talloc de-child-looping code will delete p2's reference
+          leaving p2 having a dangling pointer. p2's reference should remain */
+       /* TODO change this back to 2 when the loop detection is working */
+       CHECK_BLOCKS(__FUNCTION__, p2, 1);
+       CHECK_BLOCKS(__FUNCTION__, r1, 2);
+
+       /* if we free r1 then p2 should also vanish as it is owned by something that
+          is not owned, but we can't track that yet. Once p2 vanishes it's reference
+          to p1 should vanish letting p1 vanish.
+          We can often make sub-tree's from no-owner-context, by checking when references
+          of things child-of no-owner-context die
+       */
+       fprintf(stderr, "Freeing r1\n");
+       talloc_free(r1);
+       talloc_report_full(NULL, stderr);
+       CHECK_BLOCKS(__FUNCTION__, root, 1);
+
+       talloc_free(root);
+       printf("success: %s\n", __FUNCTION__);
+
+       talloc_report_full(NULL, stderr);
+       return true;
+}
+
+/* If take r1 reference to p2 and then free p2's owner p1
+   p2 should still be around by virtue of the reference.
+   steal p2 to p3 and free p3.
+   In current talloc p2 will be freed despite the reference.
+   In proposed talloc r1 will be the reference with no parent for p2*/
+static bool test_ref_free_steal(void)
+{
+       void *root, *p1, *p2, *p3, *ref, *r1;
+
+       printf("test: ref_free_steal\n# SINGLE REFERENCE FREE SELF FREE\n");
+
+       root = talloc_named_const(NULL, 0, "root");
+       p1 = talloc_named_const(root, 1, "p1");
+       p2 = talloc_named_const(p1, 1, "p2");
+       p3 = talloc_named_const(root, 1, "p3");
+       /* Now root owns p1, and p1 owns p2 */
+
+       r1 = talloc_named_const(root, 1, "r1");
+       ref = talloc_reference(r1, p2);
+       /* now r1 has ref reference to p2 */
+       talloc_report_full(NULL, stderr);
+
+       CHECK_BLOCKS(__FUNCTION__, p1, 2);
+       CHECK_BLOCKS(__FUNCTION__, p2, 1);
+       CHECK_BLOCKS(__FUNCTION__, p3, 1);
+       CHECK_BLOCKS(__FUNCTION__, r1, 2);
+
+       fprintf(stderr, "Freeing p1\n");
+       talloc_free(p1);
+       /* r1 should have ref reference to p2 still */
+       talloc_report_full(NULL, stderr);
+       CHECK_BLOCKS(__FUNCTION__, r1, 2);
+       CHECK_BLOCKS(__FUNCTION__, p3, 1);
+
+       /* if we talloc_steal p2 to p3, we should get an abort() */
+       fprintf(stderr, "Steal p2 to p3\n");
+       test_abort_start();
+       talloc_steal(p3, p2);
+       torture_assert(__FUNCTION__,
+                      test_abort_count == 1,
+                      "talloc_steal() didn't abort");
+       test_abort_stop();
+
+       talloc_report_full(NULL, stderr);
+       CHECK_BLOCKS(__FUNCTION__, r1, 2);
+       CHECK_BLOCKS(__FUNCTION__, p3, 1);
+
+       /* but we can reference p2 to p3 */
+       fprintf(stderr, "Steal p2 to p3\n");
+       talloc_reference(p3, p2);
+
+       talloc_report_full(NULL, stderr);
+       CHECK_BLOCKS(__FUNCTION__, r1, 2);
+       CHECK_BLOCKS(__FUNCTION__, p3, 2);
+
+       /* now we free p3 and r1 should still have a reference */
+       fprintf(stderr, "free p3\n");
+       talloc_free(p3);
+       talloc_report_full(NULL, stderr);
+       CHECK_BLOCKS(__FUNCTION__, p2, 1);
+       CHECK_BLOCKS(__FUNCTION__, r1, 2);
+
+       /* if we free r1 then p2 should also vanish */
+       fprintf(stderr, "Freeing r1\n");
+       talloc_free(r1);
+
+       talloc_report_full(NULL, stderr);
+       CHECK_BLOCKS(__FUNCTION__, NULL, 3);
+       CHECK_BLOCKS(__FUNCTION__, root, 1);
+
+       talloc_free(root);
+       CHECK_BLOCKS(__FUNCTION__, NULL, 2);
+       printf("success: ref_free_steal\n");
+       return true;
+}
+
 /*
   measure the speed of talloc versus malloc
 */
@@ -856,23 +1256,38 @@ static bool test_speed(void)
 
 static bool test_lifeless(void)
 {
-       void *top = talloc_new(NULL);
+       void *top = talloc_named_const(NULL, 0, "top");
        char *parent, *child; 
-       void *child_owner = talloc_new(NULL);
+       void *child_owner = talloc_named_const(NULL, 0, "child_owner");
 
        printf("test: lifeless\n# TALLOC_UNLINK LOOP\n");
 
        parent = talloc_strdup(top, "parent");
+       CHECK_BLOCKS("lifeless", NULL, 5);
        child = talloc_strdup(parent, "child");  
+       CHECK_BLOCKS("lifeless", NULL, 6);
        (void)talloc_reference(child, parent);
+       CHECK_BLOCKS("lifeless", NULL, 7);
        (void)talloc_reference(child_owner, child); 
-       talloc_report_full(top, stderr);
+       CHECK_BLOCKS("lifeless", NULL, 8);
+       CHECK_BLOCKS("lifeless", top, 4);
+       CHECK_BLOCKS("lifeless", child_owner, 2);
        talloc_unlink(top, parent);
+       CHECK_BLOCKS("lifeless", NULL, 8);
+       CHECK_BLOCKS("lifeless", top, 1);
+       CHECK_BLOCKS("lifeless", child_owner, 2);
+       CHECK_BLOCKS("lifeless", child, 2);
        talloc_free(child);
-       talloc_report_full(top, stderr);
+       CHECK_BLOCKS("lifeless", NULL, 8);
+       CHECK_BLOCKS("lifeless", top, 1);
+       CHECK_BLOCKS("lifeless", child_owner, 2);
+       CHECK_BLOCKS("lifeless", child, 2);
        talloc_free(top);
+       CHECK_BLOCKS("lifeless", NULL, 7);
+       CHECK_BLOCKS("lifeless", child_owner, 2);
+       CHECK_BLOCKS("lifeless", child, 2);
        talloc_free(child_owner);
-       talloc_free(child);
+       CHECK_BLOCKS("lifeless", NULL, 2);
 
        printf("success: lifeless\n");
        return true;
@@ -1103,6 +1518,13 @@ static bool test_pool(void)
        return true;
 }
 
+static void test_reset(void)
+{
+       test_abort_stop();
+       talloc_disable_null_tracking();
+       talloc_enable_null_tracking();
+}
+
 struct torture_context;
 bool torture_local_talloc(struct torture_context *tctx)
 {
@@ -1110,33 +1532,65 @@ bool torture_local_talloc(struct torture_context *tctx)
 
        setlinebuf(stdout);
 
-       talloc_disable_null_tracking();
-       talloc_enable_null_tracking();
-
+       test_reset();
        ret &= test_ref1();
+       test_reset();
        ret &= test_ref2();
+       test_reset();
        ret &= test_ref3();
+       test_reset();
        ret &= test_ref4();
+       test_reset();
        ret &= test_unlink1(); 
+       test_reset();
        ret &= test_misc();
+       test_reset();
        ret &= test_realloc();
+       test_reset();
        ret &= test_realloc_child(); 
+       test_reset();
        ret &= test_steal(); 
+       test_reset();
        ret &= test_move(); 
+       test_reset();
        ret &= test_unref_reparent();
+       test_reset();
        ret &= test_realloc_fn(); 
+       test_reset();
        ret &= test_type();
+       test_reset();
        ret &= test_lifeless(); 
+       test_reset();
        ret &= test_loop();
+       test_reset();
        ret &= test_free_parent_deny_child(); 
+       test_reset();
        ret &= test_talloc_ptrtype();
+       test_reset();
        ret &= test_talloc_free_in_destructor();
+       test_reset();
+       ret &= test_implicit_explicit_free();
+       test_reset();
+       ret &= test_ref_free_steal();
+       test_reset();
+       ret &= test_dangling_loop();
+       test_reset();
+       ret &= test_ref_free_owner();
+       test_reset();
+       ret &= test_ref_free_self();
+       test_reset();
+       ret &= test_ref_free();
+       test_reset();
        ret &= test_pool();
 
        if (ret) {
+               test_reset();
                ret &= test_speed();
        }
+       test_reset();
        ret &= test_autofree();
 
+       test_reset();
+
        return ret;
 }