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

tridge at samba.org tridge at samba.org
Wed Nov 23 00:30:59 GMT 2005


Author: tridge
Date: 2005-11-23 00:30:58 +0000 (Wed, 23 Nov 2005)
New Revision: 11870

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

Log:

fixed the problem volker reported with the RPX-XPLOGIN test. The
problem was caused by a callback destroying the packet processing
context while that context was being used in packet_recv()

This is the first time we have used the ability of talloc destructors
to 'refuse' a free request. It works well in this case as it makes the
composite API simpler to use for other code, and isolates the
complexity of having callbacks destroying the packet context to the
packet.c code.


Modified:
   branches/SAMBA_4_0/source/lib/stream/packet.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/stream/packet.c
===================================================================
--- branches/SAMBA_4_0/source/lib/stream/packet.c	2005-11-22 21:45:05 UTC (rev 11869)
+++ branches/SAMBA_4_0/source/lib/stream/packet.c	2005-11-23 00:30:58 UTC (rev 11870)
@@ -47,6 +47,9 @@
 	BOOL recv_disable;
 	BOOL nofree;
 
+	BOOL busy;
+	BOOL destructor_called;
+
 	struct send_element {
 		struct send_element *next, *prev;
 		DATA_BLOB blob;
@@ -55,11 +58,34 @@
 };
 
 /*
+  a destructor used when we are processing packets to prevent freeing of this
+  context while it is being used
+*/
+static int packet_destructor(void *p)
+{
+	struct packet_context *pc = talloc_get_type(p, struct packet_context);
+
+	if (pc->busy) {
+		pc->destructor_called = True;
+		/* now we refuse the talloc_free() request. The free will
+		   happen again in the packet_recv() code */
+		return -1;
+	}
+
+	return 0;
+}
+
+
+/*
   initialise a packet receiver
 */
 struct packet_context *packet_init(TALLOC_CTX *mem_ctx)
 {
-	return talloc_zero(mem_ctx, struct packet_context);
+	struct packet_context *pc = talloc_zero(mem_ctx, struct packet_context);
+	if (pc != NULL) {
+		talloc_set_destructor(pc, packet_destructor);
+	}
+	return pc;
 }
 
 
@@ -205,6 +231,7 @@
 	}
 }
 
+
 /*
   call this when the socket becomes readable to kick off the whole
   stream parsing process
@@ -342,8 +369,17 @@
 		pc->processing = 1;
 	}
 
+	pc->busy = True;
+
 	status = pc->callback(pc->private, blob);
 
+	pc->busy = False;
+
+	if (pc->destructor_called) {
+		talloc_free(pc);
+		return;
+	}
+
 	if (pc->processing) {
 		if (pc->processing > 1) {
 			EVENT_FD_READABLE(pc->fde);



More information about the samba-cvs mailing list