From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16093 invoked from network); 21 Feb 2003 10:18:21 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 21 Feb 2003 10:18:21 -0000 Received: (qmail 18892 invoked by alias); 21 Feb 2003 10:18:12 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 18268 Received: (qmail 18880 invoked from network); 21 Feb 2003 10:18:12 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 21 Feb 2003 10:18:12 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [62.189.183.235] by sunsite.dk (MessageWall 1.0.8) with SMTP; 21 Feb 2003 10:18:12 -0000 Received: from exchange01.csr.com (unverified) by (Content Technologies SMTPRS 4.2.1) with ESMTP id for ; Fri, 21 Feb 2003 10:25:06 +0000 Received: from csr.com (tinky-winky.csr.com [192.168.144.127]) by exchange01.csr.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2650.21) id DQ47N43N; Fri, 21 Feb 2003 10:18:31 -0000 To: zsh-workers@sunsite.dk Subject: Re: Possible ztrdup memory leaks? In-reply-to: ""John T. Guthrie""'s message of "Thu, 20 Feb 2003 07:57:54 EST." <200302201257.h1KCvsU22058@gauss.counterexample.org> Date: Fri, 21 Feb 2003 10:18:10 +0000 Message-ID: <1086.1045822690@csr.com> From: Peter Stephenson "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 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. **********************************************************************