From af23bb343a067d5346696b788f4cce5b744cd51d Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Fri, 4 Oct 2019 18:54:01 +0200 Subject: [PATCH] cwfs: fix listen filedescriptor leaks --- sys/src/cmd/cwfs/net.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/sys/src/cmd/cwfs/net.c b/sys/src/cmd/cwfs/net.c index 48d22fbf1..e9f5049ca 100644 --- a/sys/src/cmd/cwfs/net.c +++ b/sys/src/cmd/cwfs/net.c @@ -49,26 +49,28 @@ char *annstrs[Maxnets]; static void neti(void *v) { - int lisfd, accfd; NetConnInfo *nci; Network *net; + char *addr; + int nctl, data; net = v; for(;;) { - if((lisfd = listen(net->anndir, net->lisdir)) < 0){ + if((nctl = listen(net->anndir, net->lisdir)) < 0){ fprint(2, "%s: listen %s failed: %r\n", argv0, net->anndir); break; } - /* got new call on lisfd */ - if((accfd = accept(lisfd, net->lisdir)) < 0){ - fprint(2, "%s: accept %d (from %s) failed: %r\n", argv0, lisfd, net->lisdir); - close(lisfd); + if((data = accept(nctl, net->lisdir)) < 0){ + fprint(2, "%s: accept %s failed: %r\n", argv0, net->lisdir); + close(nctl); continue; } - nci = getnetconninfo(net->lisdir, accfd); - if(srvchan(accfd, nci->raddr) == nil){ - fprint(2, "%s: srvchan failed for: %s\n", argv0, nci->raddr); - close(accfd); + close(nctl); + nci = getnetconninfo(net->lisdir, data); + addr = nci == nil ? "unknown" : nci->raddr; + if(srvchan(data, addr) == nil){ + fprint(2, "%s: srvchan failed for: %s\n", argv0, addr); + close(data); } freenetconninfo(nci); }