cwfs: fix listen filedescriptor leaks
This commit is contained in:
parent
dea2905783
commit
af23bb343a
1 changed files with 12 additions and 10 deletions
|
@ -49,26 +49,28 @@ char *annstrs[Maxnets];
|
||||||
static void
|
static void
|
||||||
neti(void *v)
|
neti(void *v)
|
||||||
{
|
{
|
||||||
int lisfd, accfd;
|
|
||||||
NetConnInfo *nci;
|
NetConnInfo *nci;
|
||||||
Network *net;
|
Network *net;
|
||||||
|
char *addr;
|
||||||
|
int nctl, data;
|
||||||
|
|
||||||
net = v;
|
net = v;
|
||||||
for(;;) {
|
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);
|
fprint(2, "%s: listen %s failed: %r\n", argv0, net->anndir);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* got new call on lisfd */
|
if((data = accept(nctl, net->lisdir)) < 0){
|
||||||
if((accfd = accept(lisfd, net->lisdir)) < 0){
|
fprint(2, "%s: accept %s failed: %r\n", argv0, net->lisdir);
|
||||||
fprint(2, "%s: accept %d (from %s) failed: %r\n", argv0, lisfd, net->lisdir);
|
close(nctl);
|
||||||
close(lisfd);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
nci = getnetconninfo(net->lisdir, accfd);
|
close(nctl);
|
||||||
if(srvchan(accfd, nci->raddr) == nil){
|
nci = getnetconninfo(net->lisdir, data);
|
||||||
fprint(2, "%s: srvchan failed for: %s\n", argv0, nci->raddr);
|
addr = nci == nil ? "unknown" : nci->raddr;
|
||||||
close(accfd);
|
if(srvchan(data, addr) == nil){
|
||||||
|
fprint(2, "%s: srvchan failed for: %s\n", argv0, addr);
|
||||||
|
close(data);
|
||||||
}
|
}
|
||||||
freenetconninfo(nci);
|
freenetconninfo(nci);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue