From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3421 invoked by alias); 6 Nov 2009 21:30:17 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 27358 Received: (qmail 27824 invoked from network); 6 Nov 2009 21:30:14 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received-SPF: pass (ns1.primenet.com.au: SPF record at ntlworld.com designates 81.103.221.49 as permitted sender) Date: Fri, 6 Nov 2009 21:30:05 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: [MAYBE BUG] resetting `$0' in sourced script causes zsh to crash on Debian Message-ID: <20091106213005.372538f0@pws-pc> In-Reply-To: <200911061949.32084.stefano.lattarini@gmail.com> References: <200911061949.32084.stefano.lattarini@gmail.com> X-Mailer: Claws Mail 3.7.2 (GTK+ 2.16.6; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Cloudmark-Analysis: v=1.0 c=1 a=_JKDhcOzIqsA:10 a=pGLkceISAAAA:8 a=NLZqzBF-AAAA:8 a=Qh1Ly13EL-4IdAVifcoA:9 a=_TeTmJlS6xuuszD5jb0A:7 a=xBR3V1-ZsGTyzspRBg9PQNJ_7wUA:4 a=MSl-tDqOz04A:10 a=_dQi-Dcv4p4A:10 On Fri, 6 Nov 2009 19:49:31 +0100 Stefano Lattarini wrote: > I have recently found a problem in resetting `$0' inside a script "sourced" > with the `.' builtin. > > Not sure if it's a bug or if it's just me doing something that should not > be done; hopefully you can tell. Yep, that's a bug. Thanks for the clear instructions. The patch makes valgrind happy, and fits with your description. (If the shell didn't want you to set $0, it would declare it readonly and tell you to go it way when you set it. Since it doesn't you should be able to set it, and in either case there shouldn't be a memory error.) By the way, anyone running valgrind is invited to look at the errors in the code reported. Index: Src/builtin.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v retrieving revision 1.235 diff -u -r1.235 builtin.c --- Src/builtin.c 2 Sep 2009 15:27:35 -0000 1.235 +++ Src/builtin.c 6 Nov 2009 21:26:06 -0000 @@ -4747,7 +4747,7 @@ enam = arg0 = ztrdup(*argv); if (isset(FUNCTIONARGZERO)) { old0 = argzero; - argzero = arg0; + argzero = ztrdup(arg0); } s = unmeta(enam); errno = ENOENT; @@ -4802,8 +4802,10 @@ if (ret == SOURCE_NOT_FOUND) zwarnnam(name, "%e: %s", errno, enam); zsfree(arg0); - if (old0) + if (old0) { + zsfree(argzero); argzero = old0; + } return ret == SOURCE_OK ? lastval : 128 - ret; } -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/