zsh-workers
 help / color / mirror / code / Atom feed
From: "John T. Guthrie" <guthrie@counterexample.org>
To: zsh-workers@sunsite.dk
Subject: Re: Possible ztrdup memory leaks?
Date: Thu, 20 Feb 2003 07:57:54 -0500 (EST)	[thread overview]
Message-ID: <200302201257.h1KCvsU22058@gauss.counterexample.org> (raw)
In-Reply-To: <3175.1045737902@csr.com> from "Peter Stephenson" at Feb 20, 2003 10:45:02 AM

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@counterexample.org


  reply	other threads:[~2003-02-20 13:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-20  8:31 John T. Guthrie
2003-02-20 10:45 ` Peter Stephenson
2003-02-20 12:57   ` John T. Guthrie [this message]
2003-02-21 10:18     ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200302201257.h1KCvsU22058@gauss.counterexample.org \
    --to=guthrie@counterexample.org \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).