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

Re: Possible ztrdup memory leaks?



"John T. Guthrie" wrote:
> 
> While going through the code in exec.c, I found the following at line 2876:
> 
>     nam = ztrdup(nam);
> 
> Correct me if I'm wrong, but would this cause a memory leak?

The answer turns out to be `no' for a slightly obscure reason:  you are
correct that the value returned by the function will not be freed, since
it goes straight into the list of command arguments which is always on
the heap.

However, the line in getoutputfile()
    zaddlinknode(jobtab[thisjob].filelist, nam);
adds the name to a list of files which will be freed when the complete
job is finished executing.  This only happens after the shell is sure
the command has finished with the filename added to the command
line, so it has to use malloc memory.

The interface for which functions return freeable memory and which
don't, and for the ones that don't, how long the memory will remain
valid, is horrific.  We could do with some more debugging information
or, failing that, a complete rewrite.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************



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