svn commit: samba r6513 - in branches/SAMBA_4_0/source/lib/talloc: .
vlendec at samba.org
vlendec at samba.org
Thu Apr 28 14:54:17 GMT 2005
Author: vlendec
Date: 2005-04-28 14:54:17 +0000 (Thu, 28 Apr 2005)
New Revision: 6513
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=6513
Log:
Commit talloc_free_children.
Volker
Modified:
branches/SAMBA_4_0/source/lib/talloc/talloc.c
branches/SAMBA_4_0/source/lib/talloc/talloc_guide.txt
Changeset:
Modified: branches/SAMBA_4_0/source/lib/talloc/talloc.c
===================================================================
--- branches/SAMBA_4_0/source/lib/talloc/talloc.c 2005-04-28 07:52:32 UTC (rev 6512)
+++ branches/SAMBA_4_0/source/lib/talloc/talloc.c 2005-04-28 14:54:17 UTC (rev 6513)
@@ -461,7 +461,43 @@
return ptr;
}
+/*
+ this is a replacement for the Samba3 talloc_destroy_pool functionality. It
+ should probably not be used in new code. It's in here to keep the talloc
+ code consistent across Samba 3 and 4.
+*/
+void talloc_free_children(void *ptr)
+{
+ struct talloc_chunk *tc;
+ if (ptr == NULL) {
+ return;
+ }
+
+ tc = talloc_chunk_from_ptr(ptr);
+
+ while (tc->child) {
+ /* we need to work out who will own an abandoned child
+ if it cannot be freed. In priority order, the first
+ choice is owner of any remaining reference to this
+ pointer, the second choice is our parent, and the
+ final choice is the null context. */
+ void *child = tc->child+1;
+ const void *new_parent = null_context;
+ if (tc->child->refs) {
+ struct talloc_chunk *p = talloc_parent_chunk(tc->child->refs);
+ if (p) new_parent = p+1;
+ }
+ if (talloc_free(child) == -1) {
+ if (new_parent == null_context) {
+ struct talloc_chunk *p = talloc_parent_chunk(ptr);
+ if (p) new_parent = p+1;
+ }
+ talloc_steal(new_parent, child);
+ }
+ }
+}
+
/*
free a talloc pointer. This also frees all child pointers of this
pointer recursively
@@ -498,26 +534,7 @@
tc->destructor = NULL;
}
- while (tc->child) {
- /* we need to work out who will own an abandoned child
- if it cannot be freed. In priority order, the first
- choice is owner of any remaining reference to this
- pointer, the second choice is our parent, and the
- final choice is the null context. */
- void *child = tc->child+1;
- const void *new_parent = null_context;
- if (tc->child->refs) {
- struct talloc_chunk *p = talloc_parent_chunk(tc->child->refs);
- if (p) new_parent = p+1;
- }
- if (talloc_free(child) == -1) {
- if (new_parent == null_context) {
- struct talloc_chunk *p = talloc_parent_chunk(ptr);
- if (p) new_parent = p+1;
- }
- talloc_steal(new_parent, child);
- }
- }
+ talloc_free_children(ptr);
if (tc->parent) {
_TLIST_REMOVE(tc->parent->child, tc);
Modified: branches/SAMBA_4_0/source/lib/talloc/talloc_guide.txt
===================================================================
--- branches/SAMBA_4_0/source/lib/talloc/talloc_guide.txt 2005-04-28 07:52:32 UTC (rev 6512)
+++ branches/SAMBA_4_0/source/lib/talloc/talloc_guide.txt 2005-04-28 14:54:17 UTC (rev 6513)
@@ -106,6 +106,14 @@
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+int talloc_free_children(void *ptr);
+
+The talloc_free_children() walks along the list of all children of a
+talloc context and talloc_free()s only the children, not the context
+itself.
+
+
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void *talloc_reference(const void *context, const void *ptr);
The talloc_reference() function makes "context" an additional parent
More information about the samba-cvs
mailing list