From 4e4e698f2b59716464d2514bea3e6049170e7272 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 15 Jul 2006 14:09:21 +0000 Subject: r17062: make correct use of talloc destructors, and make the code much simpler should I merge that aslo to samba3? metze (This used to be commit c5672a54a02e3f457effd7cc693a6f6ac2dcc621) --- source4/lib/talloc/talloc.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'source4/lib/talloc') diff --git a/source4/lib/talloc/talloc.c b/source4/lib/talloc/talloc.c index 05bc09a21e..2ebaafbb83 100644 --- a/source4/lib/talloc/talloc.c +++ b/source4/lib/talloc/talloc.c @@ -237,13 +237,8 @@ void talloc_increase_ref_count(const void *ptr) */ static int talloc_reference_destructor(struct talloc_reference_handle *handle) { - struct talloc_chunk *tc1 = talloc_chunk_from_ptr(handle); - struct talloc_chunk *tc2 = talloc_chunk_from_ptr(handle->ptr); - if (tc1->destructor != (talloc_destructor_t)-1) { - tc1->destructor = NULL; - } - _TLIST_REMOVE(tc2->refs, handle); - talloc_free(handle); + struct talloc_chunk *ptr_tc = talloc_chunk_from_ptr(handle->ptr); + _TLIST_REMOVE(ptr_tc->refs, handle); return 0; } @@ -302,10 +297,7 @@ static int talloc_unreference(const void *context, const void *ptr) return -1; } - talloc_set_destructor(h, NULL); - _TLIST_REMOVE(tc->refs, h); - talloc_free(h); - return 0; + return talloc_free(h); } /* @@ -558,9 +550,15 @@ int talloc_free(void *ptr) if (tc->refs) { int is_child; - struct talloc_reference_handle *handle = tc->refs; - is_child = talloc_is_parent(handle, handle->ptr); - talloc_reference_destructor(tc->refs); + /* check this is a reference from a child or grantchild + * back to it's parent or grantparent + * + * in that case we need to remove the reference and + * call another instance of talloc_free() on the current + * pointer. + */ + is_child = talloc_is_parent(tc->refs, ptr); + talloc_free(tc->refs); if (is_child) { return talloc_free(ptr); } -- cgit