summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2006-07-15 14:09:21 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:10:10 -0500
commit4e4e698f2b59716464d2514bea3e6049170e7272 (patch)
treea9b5869728e379d17b4d1b6c990286a9961710d2
parentcab68a413b55818c3ed5003832d65f976abce28f (diff)
downloadsamba-4e4e698f2b59716464d2514bea3e6049170e7272.tar.gz
samba-4e4e698f2b59716464d2514bea3e6049170e7272.tar.bz2
samba-4e4e698f2b59716464d2514bea3e6049170e7272.zip
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)
-rw-r--r--source4/lib/talloc/talloc.c26
1 files changed, 12 insertions, 14 deletions
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);
}