rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
From: "David J. Fiander" <golem!david@uunet.UU.NET>
To: rc@archone.tamu.edu
Subject: File descriptor leak fix!
Date: Sat, 9 Nov 1991 22:19:21 -0600	[thread overview]
Message-ID: <m0kg6dr-0000MfC@golem.uucp> (raw)

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;
  	}
  }


                 reply	other threads:[~1991-11-10  6:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m0kg6dr-0000MfC@golem.uucp \
    --to=golem!david@uunet.uu.net \
    --cc=rc@archone.tamu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).