Subject: bug#34762: Acknowledgement (26.1.92; objc[27300]: Invalid or prematurely-freed autorelease pool 0x1040021e0.)

From: Caroptions Caroptions <[email-masked]>
Date: Mon, 18 Mar 2019 23:26:53 +0000

Thank you for coming back on this! I agree it is very odd, otherwise many people would experience it..

What I did, I have commented out:

  /* set main menu */

  if (needsSet)

    [NSApp setMainMenu: menu];

  // [pool release];

  unblock_input ();

}

as expected it start working fine, but not sure if it leads to memory leak ..

Also If run debug in Xcode and do step by step debugging Emacs hang this call:

          /* FIXME: we'd like to only parse the needed submenu, but this

               was causing crashes in the _common parsing code.. need to make

               sure proper initialization done.. */

/*        if (submenu && strcmp ([[submenu title] UTF8String], SSDATA (string)))

             continue; */

  submenu_start[i] = menu_items_used;

  menu_items_n_panes = 0;

  *hang*--> submenu_top_level_items[i] = parse_single_submenu (key, string, maps);

  submenu_n_panes[i] = menu_items_n_panes;

  submenu_end[i] = menu_items_used;

          n++;

  1.  In my understanding TRAMP to work with remote files starts separate thread and this thread prematurely release pool.
  2.  Another "theory" remote operations is naturally longer and file read/write much longer after 64 encode/decode, network transfer, opening local temp file and this lead to race conditions?
  3.  Or tramp include new menu item, which outside of standard event loop?

Anyway I am ready to troubleshoot and apply any patches/check code if needed.

Thanks,
Caroptions

________________________________
From: Alan Third <[email-masked]> on behalf of Alan Third <[email-masked]>
Sent: Monday, March 18, 2019 5:09 AM
To: Caroptions Caroptions
Cc: [email-masked]
Subject: Re: bug#34762: Acknowledgement (26.1.92; objc[27300]: Invalid or prematurely-freed autorelease pool 0x1040021e0.)

On Fri, Mar 15, 2019 at 08:55:49PM +0000, Caroptions Caroptions wrote:
> The bug reproduced on any compiled emacs.
>
> 26.1.92 has it, latest master branch has it... Do not understand why
> nobody else hit it as yet ..
>
> I think the problem somehow related to NSAutoreleasePool and
> pthreads : https://kenji.sx/posts/nsautoreleasepooldebian

Hi, thanks for reporting this. I didn’t get the previous email for
some reason, so I missed it.

This is an odd one. I don’t think it has anything to do with pthreads,
but I don’t really understand what’s going on. My best guess is that
somehow the autorelease pools are being drained out of order. I don’t
know why using tramp would cause that to happen.

One solution would be to remove the pool from ns_update_menubar
completely, but I assume it’s there for a good reason.
--
Alan Third