From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5011 invoked from network); 20 Feb 2003 10:45:42 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 20 Feb 2003 10:45:42 -0000 Received: (qmail 4415 invoked by alias); 20 Feb 2003 10:45:03 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 18266 Received: (qmail 4376 invoked from network); 20 Feb 2003 10:45:02 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 20 Feb 2003 10:45:02 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [62.189.183.235] by sunsite.dk (MessageWall 1.0.8) with SMTP; 20 Feb 2003 10:45:2 -0000 Received: from exchange01.csr.com (unverified) by (Content Technologies SMTPRS 4.2.1) with ESMTP id for ; Thu, 20 Feb 2003 10:51:56 +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 DQ47NQJ9; Thu, 20 Feb 2003 10:45:25 -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 03:31:22 EST." <200302200831.h1K8VMQ19431@gauss.counterexample.org> Date: Thu, 20 Feb 2003 10:45:02 +0000 Message-ID: <3175.1045737902@csr.com> From: Peter Stephenson "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 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. **********************************************************************