talloc: demonstrate memory leak in test_talloc_free_in_destructor()
authorStefan Metzmacher <metze@samba.org>
Fri, 8 Apr 2011 10:15:42 +0000 (12:15 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 17 May 2018 08:09:24 +0000 (10:09 +0200)
The problem is that level3 disappears, it's not reachable from
the null_context anymore. level3 and level5 get into a parent child loop.

I think the correct fix should be that level0 becomes the parent
of level3 after talloc_free(level1).

metze

lib/talloc/testsuite.c

index 35309e2af253a035e2653c74a6e50c838dddb686..12298a78ecc98efaf227b6ae381373ac61197ecc 100644 (file)
@@ -1229,6 +1229,7 @@ static bool test_talloc_ptrtype(void)
 
 static int _test_talloc_free_in_destructor(void **ptr)
 {
+       printf("_test_talloc_free_in_destructor\n");
        talloc_free(*ptr);
        return 0;
 }
@@ -1258,10 +1259,17 @@ static bool test_talloc_free_in_destructor(void)
 
        talloc_set_destructor(level5, _test_talloc_free_in_destructor);
 
+       talloc_report_full(NULL, stderr);
+       printf("free level1\n");
        talloc_free(level1);
 
+       talloc_report_full(NULL, stderr);
+       talloc_report_full(level3, stderr);
+       printf("free level0\n");
        talloc_free(level0);
 
+       talloc_report_full(NULL, stderr);
+
        printf("success: free_in_destructor\n");
        return true;
 }