svn commit: samba r15839 - in trunk/source: include lib

jra at samba.org jra at samba.org
Tue May 23 15:57:31 GMT 2006


Author: jra
Date: 2006-05-23 15:57:30 +0000 (Tue, 23 May 2006)
New Revision: 15839

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

Log:
Back-port tridge's talloc fixes (r15824, r15828) from Samba4.
Jeremy.

Modified:
   trunk/source/include/talloc.h
   trunk/source/lib/talloc.c


Changeset:
Modified: trunk/source/include/talloc.h
===================================================================
--- trunk/source/include/talloc.h	2006-05-23 15:57:26 UTC (rev 15838)
+++ trunk/source/include/talloc.h	2006-05-23 15:57:30 UTC (rev 15839)
@@ -140,6 +140,7 @@
 size_t talloc_get_size(const void *ctx);
 void *talloc_find_parent_byname(const void *ctx, const char *name);
 void talloc_show_parents(const void *context, FILE *file);
+int talloc_is_parent(const void *context, const char *ptr);
 
 #endif
 

Modified: trunk/source/lib/talloc.c
===================================================================
--- trunk/source/lib/talloc.c	2006-05-23 15:57:26 UTC (rev 15838)
+++ trunk/source/lib/talloc.c	2006-05-23 15:57:30 UTC (rev 15839)
@@ -540,7 +540,13 @@
 	tc = talloc_chunk_from_ptr(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);
+		if (is_child) {
+			return talloc_free(ptr);
+		}
 		return -1;
 	}
 
@@ -690,7 +696,7 @@
 
 	new_tc = talloc_chunk_from_ptr(new_ctx);
 
-	if (tc == new_tc) {
+	if (tc == new_tc || tc->parent == new_tc) {
 		return discard_const_p(void, ptr);
 	}
 
@@ -1276,7 +1282,10 @@
 			return TC_PTR_FROM_CHUNK(tc);
 		}
 		while (tc && tc->prev) tc = tc->prev;
-		tc = tc->parent;
+		if (tc) {
+			tc = tc->parent;
+		}
+
 	}
 	return NULL;
 }
@@ -1298,6 +1307,30 @@
 	while (tc) {
 		fprintf(file, "\t'%s'\n", talloc_get_name(TC_PTR_FROM_CHUNK(tc)));
 		while (tc && tc->prev) tc = tc->prev;
-		tc = tc->parent;
+		if (tc) {
+			tc = tc->parent;
+		}
 	}
 }
+
+/*
+  return 1 if ptr is a parent of context
+*/
+int talloc_is_parent(const void *context, const char *ptr)
+{
+	struct talloc_chunk *tc;
+
+	if (context == NULL) {
+		return 0;
+	}
+
+	tc = talloc_chunk_from_ptr(context);
+	while (tc) {
+		if (TC_PTR_FROM_CHUNK(tc) == ptr) return 1;
+		while (tc && tc->prev) tc = tc->prev;
+		if (tc) {
+			tc = tc->parent;
+		}
+	}
+	return 0;
+}



More information about the samba-cvs mailing list