diff options
author | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-01-30 10:34:57 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-01-30 10:34:57 +0100 |
commit | 6b4c5380d84791e18577872b7963b0fc5a0885ed (patch) | |
tree | fbf046b3aebc26e4604ebf1ecb78122b2ff1501f /sys/src/lib9p | |
parent | 2c62f8dc670b41ffc3f8205cb728857918372a0c (diff) |
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.
Diffstat (limited to 'sys/src/lib9p')
-rw-r--r-- | sys/src/lib9p/listen.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/sys/src/lib9p/listen.c b/sys/src/lib9p/listen.c index 547988472..8ba7ecb99 100644 --- 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 @@ listenproc(void *v) s->rpool = nil; s->rbuf = nil; s->wbuf = nil; + s->end = srvend; _forker(srvproc, s, 0); } free(os->addr); @@ -66,13 +68,13 @@ listenproc(void *v) 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); } |