From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 5760 invoked from network); 13 Apr 2023 14:06:11 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 13 Apr 2023 14:06:11 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1681394771; b=Z4UYUtH2E0P/1DX4AVgZY4LTVf3tN5MHuVj4m/sC0WS7O5wNYleK6rSTW9FDrTOY094yRuL867 rB7r6pMD9iCdCMil++z+zhnOdqT0gdu8jQ2DiEbXzpieJONm6pHDO2BMssuE6hZWeJP1ZN0xAg b/amRn47RPP8/XgnoQs6fdkbCDjkYsvAG6QY2weYtQBnQJ+t+6x50b4Qk1PLYl4tYMegYEg5ty nXaXO1aZzAXkyJulvI/BgjviVhyls12DUTtbfOP5agNoK8s19tdHWCITwoKm+yhL2d+vMN6K9o c1dxtl2X+zvMIdc+En6Zf0tT9arhScu7QJSj95Xappo/ww==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (smtpq1.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.96; dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256; dmarc=pass header.from=ntlworld.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1681394771; bh=DqQWTE3sK6Ggx3uWCxYKyTYTKFnY7SKjROJAfm2QdzM=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject: References:In-Reply-To:Message-ID:To:From:Date:DKIM-Signature: DKIM-Signature; b=DlVkNOg3LgOULJxGopLdqprmvNePEXeUcPkspHSDs33N8SPsWXQ7RLXYsAVaVkYwTuBTe+RZca 7vI/KMkCdVHRvHGQX3hfws23V5sgLcG7J2I3ISpz2jyAGCFLAKAhg6OKbiNIvEtLTTTn6+gqLE 1wkB/Cywz+j7OmAQHpZyFpiXMuqiecD7Z+A8cVjI8ZZfJuemscD14i7Wm+ay/iD7B0EGPGSmq4 m8cUHYy+UulLAlKaygRyq/7WXNfBWukrWq2sfOYOEHeaCdhrL5MHwLilykZC8SxVjXwhO3MakE KPRfejk0RcJ9tEkeJ/cajmPwSVR71tq3ScX9InwBTAe5Bg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:References:In-Reply-To:Message-ID:To:From: Date:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=IjXUTxCQ9eIiiZ3TwfVfWSPbD5L9EVyPwQXPkOp0qBE=; b=btdVCE/OdDsBoK07GoAxldQLjC J5Jo3PMhD5XE1I84LNK+t4LsDg+dQAKpLiDtxSmiS3B7lA5WiwAz8AzlrZh2UMvzbRB+M6VgM+kjt QlGyCMpbxnp7Hge3pLIpLfmmaD+Js07UycNu5TlehllZVJNuFldl4icJXa1bNWj+IqBtEyxCrPPgO mHNDnhKluJGX6SqogffNdYnCi9owdaHSMTgxPNVgKO9paswIbvOKiAL/nL2LOolIYo9nWjDentsTn RLaAfmmEEfpt8xo/g09h8aHM4dKsG50EPpa5MpAXQK33z4nypbO+DJoAKUrc5e+IiFnBfE02GH8o4 GbpT/Rbg==; Received: by zero.zsh.org with local id 1pmxaU-0000ER-98; Thu, 13 Apr 2023 14:06:10 +0000 Authentication-Results: zsh.org; iprev=pass (smtpq1.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.96; dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256; dmarc=pass header.from=ntlworld.com; arc=none Received: from smtpq1.tb.ukmail.iss.as9143.net ([212.54.57.96]:39850) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1pmxYF-000PsF-Hc; Thu, 13 Apr 2023 14:03:52 +0000 Received: from [212.54.57.82] (helo=smtp3.tb.ukmail.iss.as9143.net) by smtpq1.tb.ukmail.iss.as9143.net with esmtp (Exim 4.90_1) (envelope-from ) id 1pmxYF-0003OT-3X for zsh-workers@zsh.org; Thu, 13 Apr 2023 16:03:51 +0200 Received: from oxbe10.tb.ukmail.iss.as9143.net ([172.25.160.141]) by smtp3.tb.ukmail.iss.as9143.net with ESMTP id mxYFprGyQvML8mxYFpTBAn; Thu, 13 Apr 2023 16:03:51 +0200 X-Env-Mailfrom: p.w.stephenson@ntlworld.com X-Env-Rcptto: zsh-workers@zsh.org X-SourceIP: 172.25.160.141 X-CNFS-Analysis: v=2.4 cv=NuYXMeRJ c=1 sm=1 tr=0 ts=64380bc7 cx=a_exe a=f70ZRucvQZHi2l2hbwz5vQ==:117 a=wbvTLvLwOfMA:10 a=IkcTkHD0fZMA:10 a=NLZqzBF-AAAA:8 a=1K_DxvEBDa9rOKjqah8A:9 a=QEXdDO2ut3YA:10 a=RchoEgWomvYJfgJ0MydD:22 X-Authenticated-Sender: p.w.stephenson@ntlworld.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ntlworld.com; s=meg.feb2017; t=1681394631; bh=DqQWTE3sK6Ggx3uWCxYKyTYTKFnY7SKjROJAfm2QdzM=; h=Date:From:To:In-Reply-To:References:Subject; b=LfUTx53TKMpHb6a5XV9kgAu5GgQHqx1Rnk94TyzU9nzMF0sdg5iLdHK02wndUsPT+ yJwYGV/IMtsduXOQmZMKNL6U4s9bffeJG/YHJmM9rgVPqsTSZXtq1yIza8FX9uP8VS I8yx1DcAOyP6NDGKf8R9F3frP4xqJsyO5U26oC3DDKbFMfYndIOEKqmO8UOl4y4m8L 6ZxQGGN32zbpEjWw9mnhuS587oY9w8NP6tN9vL9NUMXzjeaqTYGkLGHhfCsCWUG0Va tkg3YVz9sKdHrUv+eJ7Us1sDkdAnipcGUqbjCX4156I3YDUdDT/1J2xinCU6OQS5x+ N7t7IViDq+UQA== Date: Thu, 13 Apr 2023 15:03:51 +0100 (BST) From: Peter Stephenson To: zsh-workers@zsh.org Message-ID: <2083513891.2014577.1681394631032@mail.virginmedia.com> In-Reply-To: <1865187346.2010280.1681391961060@mail.virginmedia.com> References: <48A7DCE2-AEC1-4777-949C-50917EDCECB1@kba.biglobe.ne.jp> <5C4788C8-4E40-4565-AFE8-84D57949BC8C@ntlworld.com> <267594676.4158370.1681382869709@mail.virginmedia.com> <1621107110.4161180.1681384345108@mail.virginmedia.com> <78EBC2C7-5645-4D35-B285-F140228D444C@kba.biglobe.ne.jp> <1865187346.2010280.1681391961060@mail.virginmedia.com> Subject: Re: Probabilistic crash on zsh 5.9 on x86_64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Normal X-Mailer: Open-Xchange Mailer X-Originating-IP: 147.161.167.85 X-Originating-Client: open-xchange-appsuite X-CMAE-Envelope: MS4xfL+R3Xj4CMjik1RAzxXWyfK6bjPrFYITNRfomCWMnHRW+b2MkppH3zg11CYOrRsTnLkoKIjNtnYcyae6ge+/zY9jlgY93Ug7PgTPFxf+vBfWIHNqXO+0 gG1aH0xPaMSqbnMYEOJKDaHMRSAVIDchD0Qluy214WV/zxBdsjulO8Z0HB2Pb2XyAmoL95y+s5tZYNCpoofTnuswm6SYq3FXmgkJXkmmLjg0aUNa7KTMDRfJ X-Seq: 51648 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: > On 13/04/2023 14:19 Peter Stephenson wrote: > ...not trivial... > ...hard to know... > > ...Unfortunately... > ...more complicated than that... > ...isn't trivial... Have a look at this --- it simply marks the prog in the shell function as in use earlier and unmarks it later, so the shenanigans within to do with traps all come out in the wash. So, in theory, there's not much to go wrong. But let me know... pws diff --git a/Src/exec.c b/Src/exec.c index 3b3d1235e..bf81a2a42 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -5779,12 +5779,25 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval) char *name = shfunc->node.nam; int flags = shfunc->node.flags; char *fname = dupstring(name); - Eprog prog; + Eprog prog, marked_prog; static int oflags; static int funcdepth; Heap funcheap; queue_signals(); /* Lots of memory and global state changes coming */ + /* + * In case this is a special function such as a trap, mark it + * is in use right now, so it doesn't get freed early. The + * worst that can happen is this hangs around in memory a little + * longer than strictly needed. + * + * Classic example of this happening is running TRAPEXIT directly. + * + * Because the shell function's contents may change, we'll ensure + * we use a consistent structure for use / free. + */ + marked_prog = shfunc->funcdef; + useeprog(marked_prog); NEWHEAPS(funcheap) { /* @@ -5942,6 +5955,8 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval) funcsave->fstack.filename = getshfuncfile(shfunc); prog = shfunc->funcdef; + DPUTS1(!prog->nref, "function definition %s has zero reference count", + (fname && *fname) ? fname : ""); if (prog->flags & EF_RUN) { Shfunc shf; @@ -6046,6 +6061,7 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval) } } OLDHEAPS; + freeeprog(marked_prog); unqueue_signals(); /* diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst index e0b6afb5f..de57765a0 100644 --- a/Test/C03traps.ztst +++ b/Test/C03traps.ztst @@ -1083,6 +1083,17 @@ F:Must be tested with a top-level script rather than source or function >trap1 # As of 5.7.1-test-2, the output was "out1 fn1 trap1 fn2" (on separate lines). + TRAPEXIT() { echo This is TRAPEXIT; } + TRAPEXIT + TRAPEXIT + TRAPEXIT +0:No memory problems with explicit call to TRAPEXIT. +>This is TRAPEXIT +>This is TRAPEXIT +>This is TRAPEXIT +>This is TRAPEXIT +# Three explicit calls, one implicit call at function exit. + %clean rm -f TRAPEXIT