From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#15802: 24.3.50; PUSH_HANDLER leaks memory? Date: Tue, 05 Nov 2013 11:28:00 -0500 Message-ID: References: <674ECE0A-ED5C-41A0-A4E8-417318065CC0@me.com> <54B313E1-5371-402E-A84C-246D3629F087@me.com> <02F4E04B-C60F-481D-B381-79F1F8867D59@me.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; CHARSET=US-ASCII Content-Transfer-Encoding: 7BIT X-Trace: ger.gmane.org 1383668956 3668 80.91.229.3 (5 Nov 2013 16:29:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 5 Nov 2013 16:29:16 +0000 (UTC) Cc: 15802-done@debbugs.gnu.org To: Jan =?UTF-8?Q?Dj=C3=A4rv?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Nov 05 17:29:20 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VdjVH-00063E-7l for geb-bug-gnu-emacs@m.gmane.org; Tue, 05 Nov 2013 17:29:19 +0100 Original-Received: from localhost ([::1]:57070 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VdjVG-0005FO-Ot for geb-bug-gnu-emacs@m.gmane.org; Tue, 05 Nov 2013 11:29:18 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41652) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VdjV7-0005Cz-4j for bug-gnu-emacs@gnu.org; Tue, 05 Nov 2013 11:29:14 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VdjV0-0002mV-Kc for bug-gnu-emacs@gnu.org; Tue, 05 Nov 2013 11:29:09 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:50196) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VdjV0-0002mR-H3 for bug-gnu-emacs@gnu.org; Tue, 05 Nov 2013 11:29:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1VdjV0-0005Qv-Aw for bug-gnu-emacs@gnu.org; Tue, 05 Nov 2013 11:29:02 -0500 Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Tue, 05 Nov 2013 16:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 15802 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Mail-Followup-To: 15802@debbugs.gnu.org, monnier@iro.umontreal.ca, jan.h.d@me.com Original-Received: via spool by 15802-done@debbugs.gnu.org id=D15802.138366888720809 (code D ref 15802); Tue, 05 Nov 2013 16:29:01 +0000 Original-Received: (at 15802-done) by debbugs.gnu.org; 5 Nov 2013 16:28:07 +0000 Original-Received: from localhost ([127.0.0.1]:35980 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VdjU6-0005PY-1b for submit@debbugs.gnu.org; Tue, 05 Nov 2013 11:28:06 -0500 Original-Received: from relais.videotron.ca ([24.201.245.36]:64612) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VdjU3-0005PQ-Ky for 15802-done@debbugs.gnu.org; Tue, 05 Nov 2013 11:28:04 -0500 Original-Received: from ceviche.home ([24.201.53.56]) by VL-VM-MR001.ip.videotron.ca (Oracle Communications Messaging Exchange Server 7u4-22.01 64bit (built Apr 21 2011)) with ESMTP id <0MVS00HNOTQPE2C0@VL-VM-MR001.ip.videotron.ca> for 15802-done@debbugs.gnu.org; Tue, 05 Nov 2013 11:28:02 -0500 (EST) Original-Received: by ceviche.home (Postfix, from userid 20848) id 14F086609C; Tue, 05 Nov 2013 11:28:00 -0500 (EST) In-reply-to: <02F4E04B-C60F-481D-B381-79F1F8867D59@me.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:80026 Archived-At: > The NULL case must be fairly common, i.e just one PUSH and then unwind. I'm not sure it's that common, since command_loop pushes a `top-level' catcher, so as long as we stay within command_loop_2 it doesn't go back to NULL. This said we should eliminate the NULL case by putting a "sentinel" at the beginning, so as to avoid this problem. I've done that with the patch below, Stefan === modified file 'src/ChangeLog' --- src/ChangeLog 2013-11-05 09:00:52 +0000 +++ src/ChangeLog 2013-11-05 16:26:47 +0000 @@ -1,3 +1,12 @@ +2013-11-05 Stefan Monnier + + * eval.c (handlerlist_sentinel): New variable (bug#15802). + (init_eval): Use it to ensure handlerlist is non-NULL. + (unwind_to_catch): Make sure we never set handlerlist to NULL. + (Fsignal): Adjust NULLness test of handlerlist. + + * lisp.h (PUSH_HANDLER): Assume handlerlist is non-NULL. + 2013-11-05 Xue Fuqiao * xdisp.c (syms_of_xdisp): Mention the active display table in doc === modified file 'src/eval.c' --- src/eval.c 2013-10-29 14:46:23 +0000 +++ src/eval.c 2013-11-05 16:24:40 +0000 @@ -237,11 +237,22 @@ Vrun_hooks = Qnil; } +static struct handler handlerlist_sentinel; + void init_eval (void) { specpdl_ptr = specpdl; - handlerlist = NULL; + { /* Put a dummy catcher at top-level so that handlerlist is never NULL. + This is important since handlerlist->nextfree holds the freelist + which would otherwise leak every time we unwind back to top-level. */ + struct handler *c; + handlerlist = handlerlist_sentinel.nextfree = &handlerlist_sentinel; + PUSH_HANDLER (c, Qunbound, CATCHER); + eassert (c == &handlerlist_sentinel); + handlerlist_sentinel.nextfree = NULL; + handlerlist_sentinel.next = NULL; + } Vquit_flag = Qnil; debug_on_next_call = 0; lisp_eval_depth = 0; @@ -1129,6 +1140,8 @@ { bool last_time; + eassert (catch->next); + /* Save the value in the tag. */ catch->val = value; @@ -1542,7 +1555,10 @@ } else { - if (handlerlist != 0) + if (handlerlist != &handlerlist_sentinel) + /* FIXME: This will come right back here if there's no `top-level' + catcher. A better solution would be to abort here, and instead + add a catch-all condition handler so we never come here. */ Fthrow (Qtop_level, Qt); } === modified file 'src/lisp.h' --- src/lisp.h 2013-11-05 07:11:24 +0000 +++ src/lisp.h 2013-11-05 15:48:45 +0000 @@ -2873,13 +2873,12 @@ /* Fill in the components of c, and put it on the list. */ #define PUSH_HANDLER(c, tag_ch_val, handlertype) \ - if (handlerlist && handlerlist->nextfree) \ + if (handlerlist->nextfree) \ (c) = handlerlist->nextfree; \ else \ { \ (c) = xmalloc (sizeof (struct handler)); \ (c)->nextfree = NULL; \ - if (handlerlist) \ handlerlist->nextfree = (c); \ } \ (c)->type = (handlertype); \