about summary refs log tree commit diff
path: root/Src/jobs.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2003-02-21 14:37:03 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2003-02-21 14:37:03 +0000
commitee7bdbf85d9de7e6593f5704f039d5eac26138a5 (patch)
treeec752419c1dec920e765ae5c3a31228f8cfc9b48 /Src/jobs.c
parent4e6c75fa78552ae54bad3e0fa6eebc57bb0177d3 (diff)
downloadzsh-ee7bdbf85d9de7e6593f5704f039d5eac26138a5.tar.gz
zsh-ee7bdbf85d9de7e6593f5704f039d5eac26138a5.tar.xz
zsh-ee7bdbf85d9de7e6593f5704f039d5eac26138a5.zip
18264: free job table entries properly in subshell
Diffstat (limited to 'Src/jobs.c')
-rw-r--r--Src/jobs.c62
1 files changed, 35 insertions, 27 deletions
diff --git a/Src/jobs.c b/Src/jobs.c
index eb8d24450..fba7fd26e 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -789,30 +789,28 @@ deletefilelist(LinkList file_list)
 
 /**/
 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 @@ deletejob(Job jn)
     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 @@ clearjobtab(int monitor)
     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) {