svn commit: samba r15841 - in branches/SAMBA_3_0_RELEASE: . source/include source/lib

jerry at samba.org jerry at samba.org
Tue May 23 18:40:10 GMT 2006


Author: jerry
Date: 2006-05-23 18:40:07 +0000 (Tue, 23 May 2006)
New Revision: 15841

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

Log:
grab talloc fixes (current up to r15838)
Modified:
   branches/SAMBA_3_0_RELEASE/WHATSNEW.txt
   branches/SAMBA_3_0_RELEASE/source/include/talloc.h
   branches/SAMBA_3_0_RELEASE/source/lib/talloc.c


Changeset:
Modified: branches/SAMBA_3_0_RELEASE/WHATSNEW.txt
===================================================================
--- branches/SAMBA_3_0_RELEASE/WHATSNEW.txt	2006-05-23 18:37:38 UTC (rev 15840)
+++ branches/SAMBA_3_0_RELEASE/WHATSNEW.txt	2006-05-23 18:40:07 UTC (rev 15841)
@@ -61,6 +61,8 @@
     * Instruct winbindd to ignore fd_set when select() returns -1.
     * BUG 3779: Make nmbd udp sockets non-blocking to prevent problem
       with select returning true but no data being available.
+    * Backport talloc_steal() fixes from SAMBA_4_0 (original fixes by 
+      Andrew Tridgell).
 
 
 o   Timur Bakeyev <timur at com.bat.ru>

Modified: branches/SAMBA_3_0_RELEASE/source/include/talloc.h
===================================================================
--- branches/SAMBA_3_0_RELEASE/source/include/talloc.h	2006-05-23 18:37:38 UTC (rev 15840)
+++ branches/SAMBA_3_0_RELEASE/source/include/talloc.h	2006-05-23 18:40:07 UTC (rev 15841)
@@ -139,6 +139,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: branches/SAMBA_3_0_RELEASE/source/lib/talloc.c
===================================================================
--- branches/SAMBA_3_0_RELEASE/source/lib/talloc.c	2006-05-23 18:37:38 UTC (rev 15840)
+++ branches/SAMBA_3_0_RELEASE/source/lib/talloc.c	2006-05-23 18:40:07 UTC (rev 15841)
@@ -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);
 	}
 
@@ -1278,7 +1284,10 @@
 			return TC_PTR_FROM_CHUNK(tc);
 		}
 		while (tc && tc->prev) tc = tc->prev;
-		tc = tc->parent;
+		if (tc) {
+			tc = tc->parent;
+		}
+
 	}
 	return NULL;
 }
@@ -1300,6 +1309,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