From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22742 invoked from network); 15 Jan 1999 16:03:45 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 15 Jan 1999 16:03:45 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id LAA04848; Fri, 15 Jan 1999 11:01:14 -0500 (EST) Resent-Date: Fri, 15 Jan 1999 11:01:14 -0500 (EST) Message-Id: <9901151544.AA14645@ibmth.df.unipi.it> To: "Daniel X. Pape" , zsh-workers@math.gatech.edu Subject: PATCH: zsh-3.1.5-pws-4 + typeset fix: memory leak In-Reply-To: ""Daniel X. Pape""'s message of "Fri, 15 Jan 1999 09:20:15 NFT." Date: Fri, 15 Jan 1999 16:44:19 +0100 From: Peter Stephenson Resent-Message-ID: <"406Ak.0.eB1.9Psds"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/4918 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu "Daniel X. Pape" wrote: > On Thu, 14 Jan 1999, Daniel X. Pape wrote: > > > I recently downloaded and compiled zsh-3.1.5-pws-4. However, I found a > > couple of memory leaks in builtin.c where the result of a ztrdup was > > being used as an argument, and not freed, and also where the result of a > > "promptexpand" was being passed to "unmetafy," and then that result was > > never freed. > > Here is the patch - let me know if it helps: You're certainly right about the memory leaks --- thanks. I've rewritten the patch a bit: the first part now fits in with a recent patch of mine in zsh-workers/4902, and also I don't think you actually need to duplicate the parameter name at all (somebody must simply have forgotten that createparam() does that inside). In the second case, the problem with your approach is that `print -P' can take more than one argument, and all need freeing: the easiest thing to do is use heap memory (which gets freed automatically when the builtin exits), and free the permanent memory straight away. *** Src/builtin.c.mem Thu Jan 14 15:55:34 1999 --- Src/builtin.c Fri Jan 15 16:29:33 1999 *************** *** 1560,1566 **** * Create a new node for a parameter with the flags in `on' minus the * readonly flag */ ! pm = createparam(ztrdup(pname), on & ~PM_READONLY); DPUTS(!pm, "BUG: parameter not created"); pm->ct = auxlen; if (func != BIN_EXPORT) --- 1560,1566 ---- * Create a new node for a parameter with the flags in `on' minus the * readonly flag */ ! pm = createparam(pname, on & ~PM_READONLY); DPUTS(!pm, "BUG: parameter not created"); pm->ct = auxlen; if (func != BIN_EXPORT) *************** *** 2346,2354 **** args[n] = getkeystring(args[n], &len[n], func != BIN_ECHO && !ops['e'], &nnl); /* -P option -- interpret as a prompt sequence */ ! if(ops['P']) ! args[n] = unmetafy(promptexpand(metafy(args[n], len[n], ! META_NOALLOC), 0, NULL, NULL), &len[n]); /* -D option -- interpret as a directory, and use ~ */ if(ops['D']) { Nameddir d = finddir(args[n]); --- 2346,2362 ---- args[n] = getkeystring(args[n], &len[n], func != BIN_ECHO && !ops['e'], &nnl); /* -P option -- interpret as a prompt sequence */ ! if(ops['P']) { ! /* ! * promptexpand uses permanent storage: to avoid ! * messy memory management, stick it on the heap ! * instead. ! */ ! char *str = unmetafy(promptexpand(metafy(args[n], len[n], ! META_NOALLOC), 0, NULL, NULL), &len[n]); ! args[n] = dupstring(str); ! free(str); ! } /* -D option -- interpret as a directory, and use ~ */ if(ops['D']) { Nameddir d = finddir(args[n]); -- Peter Stephenson Tel: +39 050 844536 WWW: http://www.ifh.de/~pws/ Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy