Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Possible ztrdup memory leaks?
- X-seq: zsh-workers 18267
- From: "John T. Guthrie" <guthrie@xxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: Possible ztrdup memory leaks?
- Date: Thu, 20 Feb 2003 07:57:54 -0500 (EST)
- In-reply-to: <3175.1045737902@xxxxxxx> from "Peter Stephenson" at Feb 20, 2003 10:45:02 AM
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
Peter Stephenson wrote:
> "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.
I'm sorry if I'm still a little confused. (Although I probably wasn't clear
either.) In the line nam=ztrdup(nam), the value of nam gets overwritten by a
pointer to identical contents, but the old value of nam (that is, the value
that was used as input to ztrdup()) is now lost, and never gets freed. I'm
still confused as to why this isn't a memory leak. Although you did
answer another question that I had which was why the line nam=ztrdup(nam)
was necessary in the first place.
Thanks.
John Guthrie
guthrie@xxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author