From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk
Subject: Re: Possible ztrdup memory leaks?
Date: Fri, 21 Feb 2003 10:18:10 +0000 [thread overview]
Message-ID: <1086.1045822690@csr.com> (raw)
In-Reply-To: ""John T. Guthrie""'s message of "Thu, 20 Feb 2003 07:57:54 EST." <200302201257.h1KCvsU22058@gauss.counterexample.org>
"John T. Guthrie" wrote:
> 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.
If you look inside gettempname(), which is where `name' comes from,
the return value comes from
ret = ((char *) _mktemp(dyncat(unmeta(s), "XXXXXX")));
(or the other functionally identical branch of the #if).
s is a raw parameter value or static string, so doesn't need freeing.
(getsparam() and similar function just return the string or whatever
in the parameter without copying, for efficiency.)
`dyncat' creates a concatenated string from heap memory, so doesn't
need freeing. (See mem.c for a description of heap memory.)
_mktemp simply uses the space already allocated, so the return value
doesn't need freeing.
Lots of utility functions in this neck of the words work like this. The
unusual thing about getoutputfile() is that it acquires non-freeable
memory, but needs freeable memory for the linked list of temporary
files, hences needs to ztrdup() the string it gets.
--
Peter Stephenson <pws@csr.com> 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.
**********************************************************************
prev parent reply other threads:[~2003-02-21 10:18 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
2003-02-21 10:18 ` Peter Stephenson [this message]
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=1086.1045822690@csr.com \
--to=pws@csr.com \
--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).