From nobody@FreeBSD.org  Sat Oct 27 05:57:46 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id B986637B406
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 27 Oct 2001 05:57:45 -0700 (PDT)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.4/8.11.4) id f9RCvjT18756;
	Sat, 27 Oct 2001 05:57:45 -0700 (PDT)
	(envelope-from nobody)
Message-Id: <200110271257.f9RCvjT18756@freefall.freebsd.org>
Date: Sat, 27 Oct 2001 05:57:45 -0700 (PDT)
From: Bob Bishop <rb@gid.co.uk>
To: freebsd-gnats-submit@FreeBSD.org
Subject: /bin/sh memory leak
X-Send-Pr-Version: www-1.0

>Number:         31533
>Category:       bin
>Synopsis:       /bin/sh memory leak
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    tegge
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Oct 27 06:00:02 PDT 2001
>Closed-Date:    Thu Nov 15 10:51:43 PST 2001
>Last-Modified:  Sun Nov 18 05:20:01 PST 2001
>Originator:     Bob Bishop
>Release:        4.3-RELEASE
>Organization:
GID ltd
>Environment:
FreeBSD spambox2.gid.co.uk 4.3-RELEASE FreeBSD 4.3-RELEASE #0: Sun Aug 26 23:43:16 BST 2001     rb@spambox2.gid.co.uk:/usr/src/sys/compile/SPAMBOX2  i386
>Description:
/bin/sh leaks memory under certain conditions
>How-To-Repeat:
Run the following (minimal) script, watch the shell with top(1):

#!/bin/sh
while true
do
        cd /tmp
        while true
        do
                break
        done
done
>Fix:

>Release-Note:
>Audit-Trail:

From: Bob Bishop <rb@gid.co.uk>
To: freebsd-gnats-submit@FreeBSD.org, rb@gid.co.uk
Cc:  
Subject: Re: bin/31533: /bin/sh memory leak
Date: Sat, 27 Oct 2001 16:39:58 +0100

 Also affects -CURRENT
 
 --
 Bob Bishop		    +44 (0)118 977 4017
 rb@gid.co.uk		fax +44 (0)118 989 4254
 

From: Maxim Konovalov <maxim@macomnet.ru>
To: freebsd-gnats-sumbit@freebsd.org
Cc: Bob Bishop <rb@gid.co.uk>
Subject: Re: bin/31533: /bin/sh memory leak (fwd)
Date: Mon, 29 Oct 2001 16:32:32 +0300 (MSK)

 I resend the message because there is no my followup in gnats db.
 
 ---------- Forwarded message ----------
 Date: Sat, 27 Oct 2001 20:11:25 +0400 (MSD)
 From: Maxim Konovalov <maxim@macomnet.ru>
 To: Bob Bishop <rb@gid.co.uk>
 Cc: freebsd-bugs@FreeBSD.ORG
 Subject: Re: bin/31533: /bin/sh memory leak
 
 On Sat, 27 Oct 2001, Bob Bishop wrote:
 
 > The following reply was made to PR bin/31533; it has been noted by GNATS.
 >
 > From: Bob Bishop <rb@gid.co.uk>
 > To: freebsd-gnats-submit@FreeBSD.org, rb@gid.co.uk
 > Cc:
 > Subject: Re: bin/31533: /bin/sh memory leak
 > Date: Sat, 27 Oct 2001 16:39:58 +0100
 >
 >  Also affects -CURRENT
 
 How about this patch:
 
 Index: cd.c
 ===================================================================
 RCS file: /home/ncvs/src/bin/sh/cd.c,v
 retrieving revision 1.20
 diff -u -r1.20 cd.c
 --- cd.c	29 Nov 1999 19:10:58 -0000	1.20
 +++ cd.c	27 Oct 2001 16:07:20 -0000
 @@ -238,8 +238,8 @@
  		curdir = NULL;
  		if (getpwd() == NULL)
  			error("getcwd() failed: %s", strerror(errno));
 -		setvar("PWD", curdir, VEXPORT | VTEXTFIXED);
 -		setvar("OLDPWD", prevdir, VEXPORT | VTEXTFIXED);
 +		setvar("PWD", curdir, VEXPORT);
 +		setvar("OLDPWD", prevdir, VEXPORT);
  		INTON;
  		return;
  	}
 @@ -270,8 +270,8 @@
  		ckfree(prevdir);
  	prevdir = curdir;
  	curdir = savestr(stackblock());
 -	setvar("PWD", curdir, VEXPORT | VTEXTFIXED);
 -	setvar("OLDPWD", prevdir, VEXPORT | VTEXTFIXED);
 +	setvar("PWD", curdir, VEXPORT);
 +	setvar("OLDPWD", prevdir, VEXPORT);
  	INTON;
  }
 
 -- 
 Maxim Konovalov, MAcomnet, Internet-Intranet Dept., system engineer
 phone: +7 (095) 796-9079, mailto: maxim@macomnet.ru
 
 
 

From: Bob Bishop <rb@gid.co.uk>
To: freebsd-gnats-submit@FreeBSD.org, rb@gid.co.uk
Cc: Maxim Konovalov <maxim@macomnet.ru>
Subject: Re: bin/31533: /bin/sh memory leak
Date: Mon, 29 Oct 2001 22:07:02 +0000

 [ My followup got lost as well. ]
 
 Maxim's patch appears to fix the problem. Someone please commit.
 
 
 --
 Bob Bishop              (0118) 977 4017  international code +44 118
 rb@gid.co.uk        fax (0118) 989 4254
 
 

From: Maxim Konovalov <maxim@macomnet.ru>
To: freebsd-gnats-sumbit@freebsd.org
Cc: Bob Bishop <rb@gid.co.uk>
Subject: Re: bin/31533: /bin/sh memory leak (fwd)
Date: Wed, 7 Nov 2001 11:06:20 +0300 (MSK)

 Just as follow up.
 
 >From maxim@macomnet.ru Wed Nov  7 11:03:46 2001
 Date: Mon, 5 Nov 2001 23:12:21 +0300 (MSK)
 From: Maxim Konovalov <maxim@macomnet.ru>
 To: Alfred Perlstein <bright@mu.org>
 Cc: Bob Bishop <rb@gid.co.uk>, hackers@FreeBSD.ORG
 Subject: Re: Committer please
 
 
 Hello,
 
 On Mon, 5 Nov 2001, Alfred Perlstein wrote:
 
 > * Bob Bishop <rb@gid.co.uk> [011105 06:35] wrote:
 > > Hi,
 > >
 > > Would some kind committer please have a look at bin/31533: /bin/sh memory
 > > leak. There is a patch there which I believe is OK. Having a memory leak
 > > loose in the shell seems like a Bad Idea to me. TIA
 >
 > Understandable, things like this could be applied more quickly if
 > someone would take the time to explain what the delta does other
 > than fix the problem.  Meaning, what is VTEXTFIXED, and what does
 > removing it change?
 
 OK, mea culpa.
 
 /usr/src/bin/sh/var.h:48
 
 #define VTEXTFIXED      0x08    /* text is staticly allocated */
 
 Afaiu it is used for internal variables names which are statically
 allocated in /usr/src/bin/sh/var.c:102. VTEXTFIXED prevents them from
 freing:
 
 /usr/src/bin/sh/var.c:319
 
                         if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0)
                                 ckfree(vp->text);
 
 PWD and OLDPWD variables are not statical ones and should be
 reallocated every time when changed.
 
 - -maxim
 
 -- 
 Maxim Konovalov, MAcomnet, Internet-Intranet Dept., system engineer
 phone: +7 (095) 796-9079, mailto: maxim@macomnet.ru
 
 

From: Tor.Egge@cvsup.no.freebsd.org
To: maxim@macomnet.ru
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/31533: /bin/sh memory leak (fwd)
Date: Wed, 07 Nov 2001 23:03:26 GMT

 >  PWD and OLDPWD variables are not statical ones and should be
 >  reallocated every time when changed.
 
 I introduced this leak in revision 1.18 of cd.c while fixing a
 different problem (cf. PR 2541).  I've commited your suggested fix to
 -current and will MFC it to RELENG_4 in a few days.
 
 - Tor Egge

From: Maxim Konovalov <maxim@macomnet.ru>
To: Tor.Egge@cvsup.no.freebsd.org
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/31533: /bin/sh memory leak (fwd)
Date: Thu, 8 Nov 2001 10:42:54 +0300 (MSK)

 On Wed, 7 Nov 2001 Tor.Egge@cvsup.no.freebsd.org wrote:
 
 >
 > >  PWD and OLDPWD variables are not statical ones and should be
 > >  reallocated every time when changed.
 >
 > I introduced this leak in revision 1.18 of cd.c while fixing a
 > different problem (cf. PR 2541).  I've commited your suggested fix to
 > -current and will MFC it to RELENG_4 in a few days.
 >
 > - Tor Egge
 
 Thank you!
 
 -- 
 Maxim Konovalov, MAcomnet, Internet-Intranet Dept., system engineer
 phone: +7 (095) 796-9079, mailto: maxim@macomnet.ru
 
Responsible-Changed-From-To: freebsd-bugs->tegge 
Responsible-Changed-By: billf 
Responsible-Changed-When: Thu Nov 8 02:33:56 PST 2001 
Responsible-Changed-Why:  
tegge introduced and fixed this bug. over to him to nag until MFC. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=31533 
State-Changed-From-To: open->closed 
State-Changed-By: asmodai 
State-Changed-When: Thu Nov 15 10:51:43 PST 2001 
State-Changed-Why:  
Originator says this got MFC'd. 

Thanks. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=31533 

From: Maxim Konovalov <maxim@macomnet.ru>
To: freebsd-gnats-submit@freebsd.org
Cc: Bob Bishop <rb@gid.co.uk>
Subject: Re: bin/31533: /bin/sh memory leak
Date: Sun, 18 Nov 2001 15:26:08 +0300 (MSK)

 Hello,
 
 This PR can be closed. The fix was committed to -current and -stable.
 
 - -maxim
 
 -- 
 Maxim Konovalov, MAcomnet, Internet-Intranet Dept., system engineer
 phone: +7 (095) 796-9079, mailto: maxim@macomnet.ru
 
 

From: Bob Bishop <rb@gid.co.uk>
To: freebsd-gnats-submit@freebsd.org
Cc: Maxim Konovalov <maxim@macomnet.ru>
Subject: Re: bin/31533: /bin/sh memory leak
Date: Sun, 18 Nov 2001 13:06:50 +0000

 Hi,
 
 Maxim Konovalov <maxim@macomnet.ru> wrote:
 > This PR can be closed. The fix was committed to -current and -stable.
 
 I agree with that.
 
 
 --
 Bob Bishop              (0118) 977 4017  international code +44 118
 rb@gid.co.uk        fax (0118) 989 4254
 
 
>Unformatted:
