From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5618 invoked from network); 1 Jun 2000 09:06:50 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 1 Jun 2000 09:06:50 -0000 Received: (qmail 28561 invoked by alias); 1 Jun 2000 09:06:41 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 11707 Received: (qmail 28553 invoked from network); 1 Jun 2000 09:06:40 -0000 Date: Thu, 01 Jun 2000 10:06:13 +0100 From: Peter Stephenson Subject: Re: PATCH: Memorey leak with PS4 usage. In-reply-to: "Your message of Wed, 31 May 2000 23:25:12 PDT." <20000601062512.29057.qmail@web1303.mail.yahoo.com> To: zsh-workers@sunsite.auc.dk (Zsh hackers list) Message-id: <0FVG001CLXAD60@la-la.cambridgesiliconradio.com> Content-transfer-encoding: 7BIT > > } There seems to be a memory leak issue with the use of promptexpand. > > } I've included a patch for utils.c. > I think the these lines in promptexpand: > Are not allocated off the internal heap. Yes, this needs freeing, as do the other uses in subst.c below. promptexpand always allocates its own storage, and unmetafy returns the same area of memory. I think I'll commit these, too, on the basis that if this is wrong then I ought to go and do something else like flower-arranging. Index: Src/subst.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/subst.c,v retrieving revision 1.7 diff -u -r1.7 subst.c --- Src/subst.c 2000/05/31 08:56:24 1.7 +++ Src/subst.c 2000/06/01 09:01:20 @@ -1661,18 +1661,24 @@ aval = arrdup(aval), copied = 1; ap = aval; for (; *ap; ap++) { + char *tmps; unmetafy(*ap, &len); untokenize(*ap); - *ap = unmetafy(promptexpand(metafy(*ap, len, META_NOALLOC), - 0, NULL, NULL), &len); + tmps = unmetafy(promptexpand(metafy(*ap, len, META_NOALLOC), + 0, NULL, NULL), &len); + *ap = dupstring(tmps); + free(tmps); } } else { + char *tmps; if (!copied) val = dupstring(val), copied = 1; unmetafy(val, &len); untokenize(val); - val = unmetafy(promptexpand(metafy(val, len, META_NOALLOC), + tmps = unmetafy(promptexpand(metafy(val, len, META_NOALLOC), 0, NULL, NULL), &len); + val = dupstring(tmps); + free(tmps); } opts[PROMPTSUBST] = ops; opts[PROMPTBANG] = opb; -- Peter Stephenson Cambridge Silicon Radio, Unit 300, Science Park, Milton Road, Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070