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

Re: PATCH: Memorey leak with PS4 usage.



--- Bart Schaefer <schaefer@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
> On May 31,  8:27pm, Felix Rosencrantz wrote:
> } Subject: PATCH: Memorey leak with PS4 usage.
> }
> } There seems to be a memory leak issue with the use of promptexpand.
> } I've included a patch for utils.c.
> 
> What leads you to this conclusion?
> 
> dupstring() allocates off zsh's internal heap.  Freeing a pointer off the
> heap is a Bad Thing.  The heap is allocated and freed in large chunks that
> zsh subdivides as necessary.

I think the these lines in promptexpand:
prompt.c:144:        return ztrdup("");
prompt.c:163:   bp =bufline = buf = zcalloc(bufspc = 256);

Are not allocated off the internal heap.

Also, other uses of promptexpand use free to free this space. For example,
in bin_print():
builtin.c:2758   if(ops['P']) {
builtin.c:2759       /*
builtin.c:2760        * promptexpand uses permanent storage: to avoid
builtin.c:2761        * messy memory management, stick it on the heap
builtin.c:2762        * instead.
builtin.c:2763        */
builtin.c:2764        char *str = unmetafy(promptexpand(metafy(args[n], len[n],
builtin.c:2765                               META_NOALLOC), 0, NULL, NULL),
&len[n]);
builtin.c:2766        args[n] = dupstring(str);
builtin.c:2767        free(str);
builtin.c:2768   }

Is this correct? Plus, that comment is unclear to me.  Though code speaks
louder than comments. 

-FR.


__________________________________________________
Do You Yahoo!?
Send instant messages & get email alerts with Yahoo! Messenger.
http://im.yahoo.com/



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