diff options
author | Stefan Metzmacher <metze@samba.org> | 2007-05-08 08:49:52 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:52:15 -0500 |
commit | aa4ab6d3c195ca5f0f53e5a25b0839ce8a0fa580 (patch) | |
tree | 90f2b4b99f8390cdbf8a33d1f0ed7b9bd274aa97 /source4 | |
parent | 112728c65101948204fe9a7c1373ff21f1724cdb (diff) | |
download | samba-aa4ab6d3c195ca5f0f53e5a25b0839ce8a0fa580.tar.gz samba-aa4ab6d3c195ca5f0f53e5a25b0839ce8a0fa580.tar.bz2 samba-aa4ab6d3c195ca5f0f53e5a25b0839ce8a0fa580.zip |
r22757: test if calling talloc_free() works on parent elements from within a destrutor
metze
(This used to be commit 305117fae0b4692b27b9cc7204fc59fb1312eabb)
Diffstat (limited to 'source4')
-rw-r--r-- | source4/lib/talloc/testsuite.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index d122a5de0d..587f270553 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -993,7 +993,7 @@ static bool test_talloc_ptrtype(void) s4 = talloc_array_ptrtype(top, s4, 10);location4 = __location__; if (talloc_get_size(s4) != (sizeof(struct struct1 **) * 10)) { - printf("failure: TALLOC PTRTYPE [\n" + printf("failure: ptrtype [\n" "talloc_array_ptrtype() allocated the wrong size " "%lu (should be %lu)\n]\n", (unsigned long)talloc_get_size(s4), @@ -1010,6 +1010,45 @@ static bool test_talloc_ptrtype(void) return true; } +static int _test_talloc_free_in_destructor(void **ptr) +{ + talloc_free(*ptr); + return 0; +} + +static bool test_talloc_free_in_destructor(void) +{ + void *level0; + void *level1; + void *level2; + void *level3; + void *level4; + void **level5; + + printf("test: free_in_destructor [\nTALLOC FREE IN DESTRUCTOR\n]\n"); + + level0 = talloc_new(NULL); + level1 = talloc_new(level0); + level2 = talloc_new(level1); + level3 = talloc_new(level2); + level4 = talloc_new(level3); + level5 = talloc(level4, void *); + + *level5 = level3; + (void)talloc_reference(level0, level3); + (void)talloc_reference(level3, level3); + (void)talloc_reference(level5, level3); + + talloc_set_destructor(level5, _test_talloc_free_in_destructor); + + talloc_free(level1); + + talloc_free(level0); + + printf("success: free_in_destructor\n"); + return true; +} + static bool test_autofree(void) { #if _SAMBA_BUILD_ < 4 @@ -1055,6 +1094,7 @@ bool torture_local_talloc(struct torture_context *tctx) ret &= test_loop(); ret &= test_free_parent_deny_child(); ret &= test_talloc_ptrtype(); + ret &= test_talloc_free_in_destructor(); if (ret) { ret &= test_speed(); |