zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: "Daniel X. Pape" <dpape@canis.uiuc.edu>, zsh-workers@math.gatech.edu
Subject: PATCH: zsh-3.1.5-pws-4 + typeset fix: memory leak
Date: Fri, 15 Jan 1999 16:44:19 +0100	[thread overview]
Message-ID: <9901151544.AA14645@ibmth.df.unipi.it> (raw)
In-Reply-To: ""Daniel X. Pape""'s message of "Fri, 15 Jan 1999 09:20:15 NFT." <Pine.GSO.4.05.9901150916340.3262-100000@sabine.canis.uiuc.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 <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


  reply	other threads:[~1999-01-15 16:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-01-15  2:17 Question: patch for " Daniel X. Pape
1999-01-15 15:20 ` PATCH: was " Daniel X. Pape
1999-01-15 15:44   ` Peter Stephenson [this message]
1999-01-15 16:43     ` PATCH: zsh-3.1.5-pws-4 + typeset fix: " 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=9901151544.AA14645@ibmth.df.unipi.it \
    --to=pws@ibmth.df.unipi.it \
    --cc=dpape@canis.uiuc.edu \
    --cc=zsh-workers@math.gatech.edu \
    /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).