Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

disown memory leak



I noticed this some time ago but never did anything.  Disown simply
clears the job table entry for a job without deleting any of the
associated structures.  I don't see how this can possibly be anything
other than a memory leak.

What may happen, however, is a that the job exits and is handled by
the signal handler while disown is busy deleting it (the opposite
can't happen because signals are blocked while the handler is busy).
I've therefore made deletejob() remove the process list as the first
thing; then findproc() won't find the process if the job is already
being deleted.  If you were paranoid, you might want to block signals
around deletejob().

*** Src/jobs.c.disown	Tue Jun 17 15:51:45 1997
--- Src/jobs.c	Tue Jun 17 16:12:21 1997
***************
*** 573,579 ****
  {
      struct process *pn, *nx;
  
!     for (pn = jn->procs; pn; pn = nx) {
  	nx = pn->next;
  	zfree(pn, sizeof(struct process));
      }
--- 573,581 ----
  {
      struct process *pn, *nx;
  
!     pn = jn->procs;
!     jn->procs = NULL;
!     for (; pn; pn = nx) {
  	nx = pn->next;
  	zfree(pn, sizeof(struct process));
      }
***************
*** 1139,1150 ****
  	    printjob(job + jobtab, lng, 2);
  	    break;
  	case BIN_DISOWN:
! 	    {
! 		static struct job zero;
! 
! 		jobtab[job] = zero;
! 		break;
! 	    }
  	}
  	thisjob = ocj;
      }
--- 1141,1148 ----
  	    printjob(job + jobtab, lng, 2);
  	    break;
  	case BIN_DISOWN:
! 	    deletejob(jobtab + job);
! 	    break;
  	}
  	thisjob = ocj;
      }

-- 
Peter Stephenson <pws@xxxxxx>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.



Messages sorted by: Reverse Date, Date, Thread, Author