From eu@grosbein.pp.ru  Thu Jul  4 03:18:07 2002
Return-Path: <eu@grosbein.pp.ru>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP
	id F0C1837B400; Thu,  4 Jul 2002 03:18:06 -0700 (PDT)
Received: from grosbein.pp.ru (www2.svzserv.kemerovo.su [213.184.65.86])
	by mx1.FreeBSD.org (Postfix) with ESMTP
	id A5F6743E3B; Thu,  4 Jul 2002 03:18:04 -0700 (PDT)
	(envelope-from eu@grosbein.pp.ru)
Received: from grosbein.pp.ru (smmsp@localhost [127.0.0.1])
	by grosbein.pp.ru (8.12.5/8.12.2) with ESMTP id g64AH8L5017186;
	Thu, 4 Jul 2002 18:17:08 +0800 (KRAST)
	(envelope-from eu@grosbein.pp.ru)
Received: (from root@localhost)
	by grosbein.pp.ru (8.12.5/8.12.3/Submit) id g64AGhEF017182;
	Thu, 4 Jul 2002 18:16:43 +0800 (KRAST)
Message-Id: <200207041016.g64AGhEF017182@grosbein.pp.ru>
Date: Thu, 4 Jul 2002 18:16:43 +0800 (KRAST)
From: Eugene Grosbein <eu@grosbein.pp.ru>
Reply-To: Eugene Grosbein <eu@grosbein.pp.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc: stable@freebsd.org
Subject: /bin/sh with builtin 'test' has memory leaks
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         40177
>Category:       bin
>Synopsis:       /bin/sh with builtin 'test' has memory leaks
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    maxim
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jul 04 03:20:04 PDT 2002
>Closed-Date:    Tue Sep 10 02:21:07 PDT 2002
>Last-Modified:  Tue Sep 10 02:21:07 PDT 2002
>Originator:     Eugene Grosbein
>Release:        FreeBSD 4.6-STABLE i386
>Organization:
Svyaz Service JSC
>Environment:
System: All releases with test built in /bin/sh

>Description:
	There seem to be memory leak in 'test' command that was not
	a problem when it was external command but it became a problem
	when 'test' was made builtin.

>How-To-Repeat:

	1. Make test.sh:

	#!/bin/sh

	while :
	do
	  [ 1=1 ]
	done

	2. run top in one session and 'nice ./test.sh' in another,
	see how quickly it leaks.

>Fix:

	Unknown for me. There are workarounds, though:

	1. alias test=/bin/test; alias [=/bin/[
	This will force using standalone versions of test and
	attenuate the problem.
	2. Rebuild /bin/sh without test as builtin.
	That's enough to delete last line from /usr/src/bin/sh/builtins.def
>Release-Note:
>Audit-Trail:

From: Maxim Konovalov <maxim@macomnet.ru>
To: Eugene Grosbein <eu@grosbein.pp.ru>
Cc: bug-followup@freebsd.org
Subject: Re: bin/40177: /bin/sh with builtin 'test' has memory leaks
Date: Thu, 4 Jul 2002 14:35:42 +0400 (MSD)

 Could you please try a patch below?
 
 Index: test/test.c
 ===================================================================
 RCS file: /home/ncvs/src/bin/test/test.c,v
 retrieving revision 1.29.2.5
 diff -u -r1.29.2.5 test.c
 --- test/test.c	29 Apr 2002 13:06:02 -0000	1.29.2.5
 +++ test/test.c	4 Jul 2002 10:33:31 -0000
 @@ -240,6 +240,7 @@
  		syntax(*t_wp, "unexpected operator");
  	(void)setregid(gid, egid);
  	(void)setreuid(uid, euid);
 +	free(nargv);
 
  	return res;
  }
 
 %%%
 
 -- 
 Maxim Konovalov, MAcomnet, Internet Dept., system engineer
 phone: +7 (095) 796-9079, mailto:maxim@macomnet.ru
 
 

From: Eugene Grosbein <eugen@grosbein.pp.ru>
To: Maxim Konovalov <maxim@macomnet.ru>
Cc: Eugene Grosbein <eu@grosbein.pp.ru>, bug-followup@freebsd.org,
	stable@freebsd.org
Subject: Re: bin/40177: /bin/sh with builtin 'test' has memory leaks
Date: Thu, 4 Jul 2002 19:57:24 +0800

 On Thu, Jul 04, 2002 at 02:35:42PM +0400, Maxim Konovalov wrote:
 
 > Could you please try a patch below?
 > 
 > Index: test/test.c
 > ===================================================================
 > RCS file: /home/ncvs/src/bin/test/test.c,v
 > retrieving revision 1.29.2.5
 > diff -u -r1.29.2.5 test.c
 > --- test/test.c	29 Apr 2002 13:06:02 -0000	1.29.2.5
 > +++ test/test.c	4 Jul 2002 10:33:31 -0000
 > @@ -240,6 +240,7 @@
 >  		syntax(*t_wp, "unexpected operator");
 >  	(void)setregid(gid, egid);
 >  	(void)setreuid(uid, euid);
 > +	free(nargv);
 > 
 >  	return res;
 >  }
 > 
 > %%%
 
 Yes, it works. Thank you and  Stefan Farfeleder for similar patch,
 I tried only this one, though.
 
 Eugene
State-Changed-From-To: open->patched 
State-Changed-By: maxim 
State-Changed-When: Fri Jul 5 03:30:50 PDT 2002 
State-Changed-Why:  
Fixed in rev. 1.49 src/bin/test/test.c in -current. 


Responsible-Changed-From-To: freebsd-bugs->maxim 
Responsible-Changed-By: maxim 
Responsible-Changed-When: Fri Jul 5 03:30:50 PDT 2002 
Responsible-Changed-Why:  
I will MFC the fix in one week. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=40177 

From: Maxim Konovalov <maxim@FreeBSD.org>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/40177
Date: Mon, 19 Aug 2002 16:00:57 +0400 (MSD)

 A more correct patch was committed, rev. 1.51 src/bin/test/test.c.
 
 -- 
 Maxim Konovalov, maxim@FreeBSD.org
 
State-Changed-From-To: patched->closed 
State-Changed-By: maxim 
State-Changed-When: Tue Sep 10 02:19:47 PDT 2002 
State-Changed-Why:  
Fixed in rev 1.51 and rev. 1.29.2.7 src/bin/test/test.c in -current 
and -stable. Thanks for the report. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=40177 
>Unformatted:
