git: 9front

Download patch

ref: c763e1e265dbb6dcc8f0179fc76d071ca4ed9c58
parent: e17c05d2a11aa9e856c36cb6e9264765fcfec340
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Wed Jan 30 05:34:57 EST 2013

lib9p: defer freeing srv for listensrv()

use the Srv.end callback for freeing the srv and closing the
file descriptor of a connection. this makes sure we wont free
the srv while there are still outstanding requests that would
access the srv when doing the respond() call.

--- a/sys/src/lib9p/listen.c
+++ b/sys/src/lib9p/listen.c
@@ -7,6 +7,7 @@
 
 static void listenproc(void*);
 static void srvproc(void*);
+static void srvend(Srv *);
 static char *getremotesys(char*);
 
 void
@@ -57,6 +58,7 @@
 		s->rpool = nil;
 		s->rbuf = nil;
 		s->wbuf = nil;
+		s->end = srvend;
 		_forker(srvproc, s, 0);
 	}
 	free(os->addr);
@@ -66,13 +68,13 @@
 static void
 srvproc(void *v)
 {
-	int data;
-	Srv *s;
-	
-	s = v;
-	data = s->infd;
-	srv(s);
-	close(data);
+	srv((Srv*)v);
+}
+
+static void
+srvend(Srv *s)
+{
+	close(s->infd);
 	free(s->addr);
 	free(s);
 }
--