svn commit: samba r2737 - in branches/SAMBA_4_0/source/lib: .

tridge at samba.org tridge at samba.org
Tue Sep 28 21:41:33 GMT 2004


Author: tridge
Date: 2004-09-28 21:41:33 +0000 (Tue, 28 Sep 2004)
New Revision: 2737

WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/branches/SAMBA_4_0/source/lib&rev=2737&nolog=1

Log:
fixed up a corner case where talloc_unreference() and talloc_free()
might not place the pointer in the context specified in the docs. The
code was assuming that pointer was at the head of the child list,
which it may not be, depending on what other operations have happened
in between.


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


Changeset:
Modified: branches/SAMBA_4_0/source/lib/talloc.c
===================================================================
--- branches/SAMBA_4_0/source/lib/talloc.c	2004-09-28 21:30:54 UTC (rev 2736)
+++ branches/SAMBA_4_0/source/lib/talloc.c	2004-09-28 21:41:33 UTC (rev 2737)
@@ -63,6 +63,17 @@
 	return tc;
 }
 
+
+/*
+  return the parent chunk of a pointer
+*/
+static struct talloc_chunk *talloc_parent_chunk(const void *ptr)
+{
+	struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr);
+	while (tc->prev) tc=tc->prev;
+	return tc->parent;
+}
+
 /* 
    Allocate a bit of memory as a child of an existing pointer
 */
@@ -185,8 +196,7 @@
 	}
 
 	for (h=tc->refs;h;h=h->next) {
-		struct talloc_chunk *tc2 = talloc_chunk_from_ptr(h);
-		const void *parent = tc2->parent?tc2->parent+1:null_context;
+		const void *parent = talloc_parent_chunk(h);
 		if (parent == context) break;
 	}
 	if (h == NULL) {
@@ -354,11 +364,12 @@
 		void *child = tc->child+1;
 		const void *new_parent = null_context;
 		if (tc->child->refs) {
-			struct talloc_chunk *ref = talloc_chunk_from_ptr(tc->child->refs);
-			if (ref->parent) new_parent = ref->parent+1;
+			struct talloc_chunk *p = talloc_parent_chunk(tc->child->refs);
+			if (p) new_parent = p+1;
 		}
-		if (new_parent == null_context && tc->parent) {
-			new_parent = tc->parent+1;
+		if (new_parent == null_context) {
+			struct talloc_chunk *p = talloc_parent_chunk(ptr);
+			if (p) new_parent = p+1;
 		}
 		talloc_free(talloc_steal(new_parent, child));
 	}



More information about the samba-cvs mailing list