From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Win Treese Newsgroups: gmane.emacs.bugs Subject: bug#34762: Acknowledgement (26.1.92; objc[27300]: Invalid or prematurely-freed autorelease pool 0x1040021e0.) Date: Thu, 3 Sep 2020 21:44:57 -0400 Message-ID: <5E4CFA2E-BF8D-4F32-9FDA-80A004192288@acm.org> References: Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.15\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_D0B91DCC-B9BF-451B-AB18-D057566DB173" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12581"; mail-complaints-to="usenet@ciao.gmane.io" To: 34762@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 04 03:46:09 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kE0no-0003AP-Q5 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 04 Sep 2020 03:46:08 +0200 Original-Received: from localhost ([::1]:45530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kE0nn-0007VF-ML for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 03 Sep 2020 21:46:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:32778) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kE0nh-0007V6-T1 for bug-gnu-emacs@gnu.org; Thu, 03 Sep 2020 21:46:01 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:53314) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kE0nh-0007wm-K6 for bug-gnu-emacs@gnu.org; Thu, 03 Sep 2020 21:46:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kE0nh-0000vR-It for bug-gnu-emacs@gnu.org; Thu, 03 Sep 2020 21:46:01 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Win Treese Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 04 Sep 2020 01:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 34762 X-GNU-PR-Package: emacs Original-Received: via spool by 34762-submit@debbugs.gnu.org id=B34762.15991839073491 (code B ref 34762); Fri, 04 Sep 2020 01:46:01 +0000 Original-Received: (at 34762) by debbugs.gnu.org; 4 Sep 2020 01:45:07 +0000 Original-Received: from localhost ([127.0.0.1]:36627 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kE0mo-0000uE-De for submit@debbugs.gnu.org; Thu, 03 Sep 2020 21:45:06 -0400 Original-Received: from forward3-smtp.messagingengine.com ([66.111.4.237]:35163) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kE0mm-0000tO-2L for 34762@debbugs.gnu.org; Thu, 03 Sep 2020 21:45:04 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailforward.nyi.internal (Postfix) with ESMTP id BB98819402A8 for <34762@debbugs.gnu.org>; Thu, 3 Sep 2020 21:44:58 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 03 Sep 2020 21:44:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=4jtwcbXRKj8pg2kaJr2J4v0ms9MX2 AJbHWrKBUegWJk=; b=V+KsPblF+aEl+i+CEeQYnwBm2WNr7v3Vo722sKukKm5FK PzTJNAh+4iA8jrvw0nhFQu1FeGFPB2QuYhgRNteLGbXCNCBpdR9c6l7dDUYhsx/6 r93rvrxZ8kusRoovx4vobVb6xX47gw7m4YvTsJPiLe3nKevyiBVQ9TCB7ulNYE52 GwUca81iijkW6EVyOmgmA6kS6jNDGezRH0MSzlH9G7tr1WX3HAyozIKqw9jkUwvQ b/AlxUEmyXMtOBpvYwobMQ09w1dnjzWl/cMH70EZNA/e5sQvNN0UvyvIxAgPSBz0 vPhty1mEPPhbuUf3gwN+L91L2n5s7lB+33mIGDyYA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrudegvddgheduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhtggguffkfffvofesmhdtmherhh dtvdenucfhrhhomhephghinhcuvfhrvggvshgvuceothhrvggvshgvsegrtghmrdhorhhg qeenucggtffrrghtthgvrhhnpeevgfejgfehheetieeiteevjedtueettddtudefieefhf evheefhfettdeftdfhteenucffohhmrghinhepmhgvlhhprgdrohhrghdpghhnuhdrohhr ghdpghhithhhuhgsrdgtohhmnecukfhppedutdekrdegledrudehuddrudefleenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehtrhgvvghsvges rggtmhdrohhrgh X-ME-Proxy: Original-Received: from cirocco.treese.org (pool-108-49-151-139.bstnma.fios.verizon.net [108.49.151.139]) by mail.messagingengine.com (Postfix) with ESMTPA id 2E2FA3060057 for <34762@debbugs.gnu.org>; Thu, 3 Sep 2020 21:44:58 -0400 (EDT) X-Mao-Original-Outgoing-Id: 620876697.464546-44ca503f7d2fbc2090159d27c254bfdb X-Mailer: Apple Mail (2.3445.104.15) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:187053 Archived-At: --Apple-Mail=_D0B91DCC-B9BF-451B-AB18-D057566DB173 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii [This is the first time I have submitted a patch, so please let me know = if I should do something differently.] This message includes a patch for bug#34762. I think that this is also = the problem for bug#26982, previously marked wontfix. The problem seems to be with the memory management for the EmacsMenu = object. Here's what I think is going on with memory management in = ns_update_panel: 1. The code sets up an autorelease pool at line 125 2. The only NS object allocated is an EmacsMenu at line 136 3. If that allocation happens, the new object is set as the application = main menu at line 455 So the allocated menu object lasts beyond the life of the pool. The pool seems to be pretty much irrelevant in this particular case. = Since the menu is given to the app, and might be deallocated under some = circumstances if it's passed back to ns_update_menu, it seems like = simply removing the pool code is sufficient without causing a memory = leak. I have attached a patch against Emacs head for it, although the same = patch applies to the Emacs 26 code in Aquamacs. An Aquamacs user provided a test case, with some help from the team that = does the poly-R package. I reduced the test case to a standalone piece = of elisp that can be loaded. It installs packages for demonstrating the = bug, but it does in /tmp so it doesn't interfere with actual = configuration. ;; Set up to reproduce a crash in the Mac menu code ;; Load/evaluate this file in Emacs started with -q, then click on the = menu bar. ;; This code installs some packages in a temporary user-package-dir. (if (boundp 'aquamacs-version) (setq package-user-dir "/tmp/emacs-bug-test-packages-aquamacs") (setq package-user-dir "/tmp/emacs-bug-test-packages")) (make-directory package-user-dir t) (setq package-archives '(("melpa-stable" . = "https://stable.melpa.org/packages/") ("gnu" . "https://elpa.gnu.org/packages/"))) (package-initialize) (package-refresh-contents) (dolist (pkg '(ess poly-R)) (unless (package-installed-p pkg) (package-install pkg))) (require 'poly-R) (message "Run 'M-x R', then try clicking on the menu bar") ;; End test code The crash is immediate when you click on the menu bar, and does not = happen with the patch applied. There is some chance of a memory leak if = I didn't fully understand the object lifecycles. This is also tracked as Aquamacs bug #180 on github: = https://github.com/aquamacs-emacs/aquamacs-emacs/issues/180 - Win --Apple-Mail=_D0B91DCC-B9BF-451B-AB18-D057566DB173 Content-Disposition: attachment; filename=0001-nsmenu.m.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-nsmenu.m.patch" Content-Transfer-Encoding: 7bit diff --git a/ChangeLog.3 b/ChangeLog.3 index 1a53011899..5d16bbf66b 100644 --- a/ChangeLog.3 +++ b/ChangeLog.3 @@ -1,3 +1,10 @@ +2020-09-03 Win Treese + + Fix crash from clicking on menu bar (bug#34762, bug#26982). + + * src/nsmenu.m (ns_update_menubar): Remove extraneous use of + autorelease pool. + 2020-08-03 Phil Sainty lisp/so-long.el: Improve support for major mode hooks diff --git a/src/nsmenu.m b/src/nsmenu.m index e313fc03f4..a286a80da1 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m @@ -122,7 +122,6 @@ /*fprintf (stderr, "ns_update_menubar: frame: %p\tdeep: %d\tsub: %p\n", f, deep_p, submenu); */ block_input (); - pool = [[NSAutoreleasePool alloc] init]; /* Menu may have been created automatically; if so, discard it. */ if ([menu isKindOfClass: [EmacsMenu class]] == NO) @@ -240,7 +239,6 @@ [[submenu title] UTF8String]); discard_menu_items (); unbind_to (specpdl_count, Qnil); - [pool release]; unblock_input (); return; } @@ -298,7 +296,6 @@ free_menubar_widget_value_tree (first_wv); discard_menu_items (); unbind_to (specpdl_count, Qnil); - [pool release]; unblock_input (); return; } @@ -364,7 +361,6 @@ if (NILP (items)) { free_menubar_widget_value_tree (first_wv); - [pool release]; unblock_input (); return; } @@ -395,7 +391,6 @@ if (i == n) { free_menubar_widget_value_tree (first_wv); - [pool release]; unblock_input (); return; } @@ -454,7 +449,6 @@ if (needsSet) [NSApp setMainMenu: menu]; - [pool release]; unblock_input (); } --Apple-Mail=_D0B91DCC-B9BF-451B-AB18-D057566DB173 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail=_D0B91DCC-B9BF-451B-AB18-D057566DB173--