shithub: riscv

Download patch

ref: af23bb343a067d5346696b788f4cce5b744cd51d
parent: dea290578377f1d0a8691072557e8653f27b14a9
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri Oct 4 14:54:01 EDT 2019

cwfs: fix listen filedescriptor leaks

--- a/sys/src/cmd/cwfs/net.c
+++ b/sys/src/cmd/cwfs/net.c
@@ -49,26 +49,28 @@
 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);
 	}