From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relay2.UU.NET ([137.39.1.7]) by archone.tamu.edu with SMTP id <18984>; Sun, 10 Nov 1991 00:12:46 -0600 Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay2.UU.NET with SMTP (5.61/UUNET-internet-primary) id AA29684; Sun, 10 Nov 91 01:12:32 -0500 Received: from scocan.UUCP by uunet.uu.net with UUCP/RMAIL (queueing-rmail) id 011151.13411; Sun, 10 Nov 1991 01:11:51 EST Received: from golem by scocan.scocan.sco.COM id aa15573; 10 Nov 91 0:46 EST Received: by golem.uucp (/\==/\ Smail3.1.22.1 #22.12) id ; Sat, 9 Nov 1991 23:19 -0500 Message-Id: To: rc@archone.tamu.edu Subject: File descriptor leak fix! Date: Sat, 9 Nov 1991 22:19:21 -0600 From: "David J. Fiander" Well, that was fast. Here's a patch both demonstrating, and fixing the problem. I used <{} to get the current version out of the SCCS file, and as you can see, the "original" file is getting bigger all the time (I used the old shell). The patch which fixes the problem follows. - David *** /dev/fd/5 Sat Jan 26 16:57:32 1991 --- glom.h Sat Nov 9 22:53:39 1991 *************** *** 9,14 **** --- 9,18 ---- struct Fq { int pid; + #ifndef DEVFD char *name; + #else + int fd; + #endif Fq *n; }; *** /dev/fd/6 Sat Jan 26 16:57:33 1991 --- glom.c Sat Nov 9 23:14:10 1991 *************** *** 407,413 **** --- 407,415 ---- #else static List *mkcmdarg(Node *n) { char *name, buf[32]; + Fq *f = nnew(Fq); List *ret = nnew(List); + int pid; int p[2]; if (pipe(p) < 0) { *************** *** 415,421 **** return NULL; } ! if (rc_fork() == 0) { setsigdefaults(); if (dup2(p[n->u[0].i == FROM], n->u[0].i == FROM) < 0) { /* stupid hack */ --- 417,423 ---- return NULL; } ! if ((pid = rc_fork()) == 0) { setsigdefaults(); if (dup2(p[n->u[0].i == FROM], n->u[0].i == FROM) < 0) { /* stupid hack */ *************** *** 431,436 **** --- 433,444 ---- name = sprint(buf, "/dev/fd/%d", p[n->u[0].i != FROM]); name = ncpy(name); /* ncpy evaluates the expression twice */ + + f->pid = pid; + f->fd = p[n->u[0].i != FROM]; + f->n = fifoq; + fifoq = f; + ret->w = name; ret->m = NULL; ret->n = NULL; *** /dev/fd/7 Sat Jan 26 16:57:33 1991 --- utils.c Sat Nov 9 22:57:58 1991 *************** *** 294,300 **** --- 294,304 ---- while (fifoq != NULL) { rc_wait4(fifoq->pid, &sp); statprint(sp); + #ifndef DEVFD unlink(fifoq->name); + #else + close(fifoq->fd); + #endif fifoq = fifoq->n; } }