zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: PATCH: job table in subshells
Date: Wed, 19 Feb 2003 21:40:53 +0000	[thread overview]
Message-ID: <20030219214058.8B8B81B76A@pwstephenson.fsnet.co.uk> (raw)

This was my go at trying not to leak memory when entering subshells in
response to the valgrind reports produced by Felix.

The completion one is going to be difficult.

The termcap one may not strictly be a bug: from the line numbers, it is
being told to allocate its own buffer, and the interface doesn't provide
any way to free it.

The remaining one (spaceinline()) is probably going to require some work
to find: the message is from when the line allocated by zle for editing
is reallocated to increase its size.  If it's real, I suspect it's a
symptom of something going wrong somewhere else which uses the pointer.
(Presumably we would know fairly soon if realloc() was broken.)

Index: Src/jobs.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v
retrieving revision 1.18
diff -u -r1.18 jobs.c
--- Src/jobs.c	27 Aug 2002 21:10:34 -0000	1.18
+++ Src/jobs.c	17 Feb 2003 22:28:05 -0000
@@ -789,30 +789,28 @@
 
 /**/
 void
-deletejob(Job jn)
+freejob(Job jn, int deleting)
 {
     struct process *pn, *nx;
 
-    if (jn->stat & STAT_ATTACH) {
-	attachtty(mypgrp);
-	adjustwinsize(0);
-    }
-
     pn = jn->procs;
     jn->procs = NULL;
     for (; pn; pn = nx) {
 	nx = pn->next;
 	zfree(pn, sizeof(struct process));
     }
-    deletefilelist(jn->filelist);
 
     if (jn->ty)
 	zfree(jn->ty, sizeof(struct ttyinfo));
     if (jn->pwd)
 	zsfree(jn->pwd);
     jn->pwd = NULL;
-    if (jn->stat & STAT_WASSUPER)
-	deletejob(jobtab + jn->other);
+    if (jn->stat & STAT_WASSUPER) {
+	if (deleting)
+	    deletejob(jobtab + jn->other);
+	else
+	    freejob(jobtab + jn->other, 0);
+    }
     jn->gleader = jn->other = 0;
     jn->stat = jn->stty_in_env = 0;
     jn->procs = NULL;
@@ -820,6 +818,24 @@
     jn->ty = NULL;
 }
 
+/*
+ * We are actually finished with this job, rather
+ * than freeing it to make space.
+ */
+
+/**/
+void
+deletejob(Job jn)
+{
+    deletefilelist(jn->filelist);
+    if (jn->stat & STAT_ATTACH) {
+	attachtty(mypgrp);
+	adjustwinsize(0);
+    }
+
+    freejob(jn, 1);
+}
+
 /* add a process to the current job */
 
 /**/
@@ -975,24 +991,16 @@
     int i;
 
     for (i = 1; i < MAXJOB; i++) {
-	if (jobtab[i].ty) {
-	    zfree(jobtab[i].ty, sizeof(struct ttyinfo));
-	    jobtab[i].ty = NULL;
-	}
-	if (jobtab[i].pwd) {
-	    zsfree(jobtab[i].pwd);
-	    jobtab[i].pwd = NULL;
-	}
-	if (monitor) {
-	    /*
-	     * See if there is a jobtable worth saving.
-	     * We never free the saved version; it only happens
-	     * once for each subshell of a shell with job control,
-	     * so doesn't create a leak.
-	     */
-	    if (jobtab[i].stat)
-		oldmaxjob = i+1;
-	}
+	/*
+	 * See if there is a jobtable worth saving.
+	 * We never free the saved version; it only happens
+	 * once for each subshell of a shell with job control,
+	 * so doesn't create a leak.
+	 */
+	if (monitor && jobtab[i].stat)
+	    oldmaxjob = i+1;
+	else if (jobtab[i].stat & STAT_INUSE)
+	    freejob(jobtab + i, 0);
     }
 
     if (monitor && oldmaxjob) {

-- 
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Work: pws@csr.com
Web: http://www.pwstephenson.fsnet.co.uk


                 reply	other threads:[~2003-02-19 21:39 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=20030219214058.8B8B81B76A@pwstephenson.fsnet.co.uk \
    --to=pws@pwstephenson.fsnet.co.uk \
    --cc=zsh-workers@sunsite.dk \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).