zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@cambridgesiliconradio.com>
To: zsh-workers@sunsite.auc.dk (Zsh hackers list)
Subject: Re: PATCH: Memorey leak with PS4 usage.
Date: Thu, 01 Jun 2000 10:06:13 +0100	[thread overview]
Message-ID: <0FVG001CLXAD60@la-la.cambridgesiliconradio.com> (raw)
In-Reply-To: "Your message of Wed, 31 May 2000 23:25:12 PDT." <20000601062512.29057.qmail@web1303.mail.yahoo.com>

> > } 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 <pws@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


  reply	other threads:[~2000-06-01  9:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-06-01  6:25 Felix Rosencrantz
2000-06-01  9:06 ` Peter Stephenson [this message]
  -- strict thread matches above, loose matches on Subject: below --
2000-06-01  3:27 Felix Rosencrantz
2000-06-01  5:45 ` Bart Schaefer

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=0FVG001CLXAD60@la-la.cambridgesiliconradio.com \
    --to=pws@cambridgesiliconradio.com \
    --cc=zsh-workers@sunsite.auc.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).