Author: metze
Date: 2006-07-15 14:09:21 +0000 (Sat, 15 Jul 2006)
New Revision: 17062

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=17062

Log:
make correct use of talloc destructors, and make the code much simpler

should I merge that aslo to samba3?

metze
Modified:
   branches/SAMBA_4_0/source/lib/talloc/talloc.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/talloc/talloc.c
===================================================================
--- branches/SAMBA_4_0/source/lib/talloc/talloc.c       2006-07-15 13:28:52 UTC 
(rev 17061)
+++ branches/SAMBA_4_0/source/lib/talloc/talloc.c       2006-07-15 14:09:21 UTC 
(rev 17062)
@@ -237,13 +237,8 @@
 */
 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 @@
                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 @@
 
        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);
                }

Reply via email to