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

Re: Mem leak



Andrei Tcherepanov wrote:
> I link zsh (3.1.2 + some patches on jobs.c) with purify 
> and found 2 memory leaks
...
> PureLA: 2 simple licenses, 10 users.  Please remedy.

i think i'll leave this one...

> MLK: 3992 bytes leaked in 124 blocks
>   * This memory was allocated from:
> 	malloc         [/home/tandr/tmp/zsh-3.1.2/Src/rtlib.o]
> 	zalloc         [/home/tandr/tmp/zsh-3.1.2/Src/mem.c:378]
> 	listmatches    [/home/tandr/tmp/zsh-3.1.2/Src/Zle/zle_tricky.c:3571]

This is actually a call to ncalloc(), which could be set to either
heap or permanent allocation.  Looking at the code, I think it's
always supposed to allocate memory from the stack here.

> MLK: 1010 bytes leaked in 2 blocks
>   * This memory was allocated from:
> 	malloc         [/home/tandr/tmp/zsh-3.1.2/Src/rtlib.o]
> 	zalloc         [/home/tandr/tmp/zsh-3.1.2/Src/mem.c:378]
> 	metafy         [/home/tandr/tmp/zsh-3.1.2/Src/utils.c:2655]
> 	createparamtable [/home/tandr/tmp/zsh-3.1.2/Src/params.c:116]

This is where environment variables are assigned to internal
parameters.  It could be the leaky values were of arrays of some sort,
since they're 693 and 317 bytes.  My guess is that they are PATH and
some friend of its: colonarrsetfn() is called in exactly the same
circumstances as any other function for setting a string, but unlike
the normal case doesn't remember the value passed, so should delete
it.  I've confirmed the leak with `repeat 100 PATH=$PATH':  before, I
was repeatedly gaining 6 to 10kb, after the patch, I'm not.  This was
potentially a nasty one, just as well someone found it.

I can't necessarily vouch for the other parameter setting functions,
either.

*** Src/Zle/zle_tricky.c.leak	Sun Jun  1 08:42:50 1997
--- Src/Zle/zle_tricky.c	Tue Jun 24 11:35:11 1997
***************
*** 3567,3574 ****
  		    nicezputs(*ap, shout);
  		    nicezputs(fsuf, shout);
  		    t2 = nfpl + niceztrlen(*ap) + nfsl;
! 		    pb = (char *) ncalloc((prpre ? strlen(prpre) : 0) + 3 +
! 					  strlen(fpre) + strlen(*ap) + strlen(fsuf));
  		    sprintf(pb, "%s%s%s%s",
  			    (prpre && *prpre) ? prpre : "./", fpre, *ap, fsuf);
  		}
--- 3567,3574 ----
  		    nicezputs(*ap, shout);
  		    nicezputs(fsuf, shout);
  		    t2 = nfpl + niceztrlen(*ap) + nfsl;
! 		    pb = (char *) halloc((prpre ? strlen(prpre) : 0) + 3 +
! 					 strlen(fpre) + strlen(*ap) + strlen(fsuf));
  		    sprintf(pb, "%s%s%s%s",
  			    (prpre && *prpre) ? prpre : "./", fpre, *ap, fsuf);
  		}
*** Src/params.c.leak	Tue Jun  3 07:58:29 1997
--- Src/params.c	Tue Jun 24 12:13:44 1997
***************
*** 1350,1355 ****
--- 1350,1356 ----
      *dptr = x ? colonsplit(x, pm->flags & PM_UNIQUE) : mkarray(NULL);
      if (pm->ename)
  	arrfixenv(pm->nam, *dptr);
+     zsfree(x);
  }
  
  /**/

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