* File descriptor leak fix!
@ 1991-11-10 4:19 David J. Fiander
0 siblings, 0 replies; only message in thread
From: David J. Fiander @ 1991-11-10 4:19 UTC (permalink / raw)
To: rc
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;
}
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1991-11-10 6:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-11-10 4:19 File descriptor leak fix! David J. Fiander
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).