Subject: bug#12247: 24.2.50; Leak in NextStep autorelease

From: Ivan Andrus <[email-masked]>
Date: Tue, 21 Aug 2012 15:49:24 +0200

Starting from `emacs -Q` with a NextStep build (well, Cocoa actually)
run M-x shell RET and every half second the following message is printed
to the console:

2012-08-21 12:26:07.872 Emacs[58915:3403] *** __NSAutoreleaseNoPool(): Object 0x1007c9200 of class NSEvent autoreleased with no pool in place - just leaking

Setting the environment variable NSAutoreleaseHaltOnNoPool=YES and
running under gdb I get the following backtrace:

Program received signal SIGTRAP, Trace/breakpoint trap.
[Switching to process 59016]
0x00007fff81ab8d61 in __NSAutoreleaseNoPool ()
(gdb) thread apply all bt

Thread 5 (process 59016):
#0  0x00007fff80bb2a2a in __workq_kernreturn ()
#1  0x00007fff80bb2e3c in _pthread_wqthread ()
#2  0x00007fff80bb2aa5 in start_wqthread ()

Thread 4 (process 59016):
#0  0x00007fff81ab8d61 in __NSAutoreleaseNoPool ()
#1  0x00007fff81a03e79 in _CFAutoreleasePoolAddObject ()
#2  0x00007fff81a03be6 in -[NSObject(NSObject) autorelease] ()
#3  0x00007fff8659265e in +[NSEvent otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:] ()
#4  0x000000010018eb6e in ns_send_appdefined (value=<value temporarily unavailable, due to optimizations>) at nsterm.m:3394
#5  0x000000010019079a in -[EmacsApp fd_handler:] (self=<value temporarily unavailable, due to optimizations>, _cmd=<value temporarily unavailable, due to optimizations>, unused=<value temporarily unavailable, due to optimizations>) at nsterm.m:4653
#6  0x00007fff82d91114 in __NSThread__main__ ()
#7  0x00007fff80bd1fd6 in _pthread_start ()
#8  0x00007fff80bd1e89 in thread_start ()

Thread 3 (process 59016):
#0  0x00007fff80bb2a2a in __workq_kernreturn ()
#1  0x00007fff80bb2e3c in _pthread_wqthread ()
#2  0x00007fff80bb2aa5 in start_wqthread ()

Thread 2 (process 59016):
#0  0x00007fff80bb1c0a in kevent ()
#1  0x00007fff80bb3add in _dispatch_mgr_invoke ()
#2  0x00007fff80bb37b4 in _dispatch_queue_invoke ()
#3  0x00007fff80bb32de in _dispatch_worker_thread2 ()
#4  0x00007fff80bb2c08 in _pthread_wqthread ()
#5  0x00007fff80bb2aa5 in start_wqthread ()

Thread 1 (process 59016):
#0  0x00007fff80b98d7a in mach_msg_trap ()
#1  0x00007fff80b993ed in mach_msg ()
#2  0x00007fff819fa902 in __CFRunLoopRun ()
#3  0x00007fff819f9d8f in CFRunLoopRunSpecific ()
#4  0x00007fff890bb7ee in RunCurrentEventLoopInMode ()
#5  0x00007fff890bb5f3 in ReceiveNextEventCommon ()
#6  0x00007fff890bb4ac in BlockUntilNextEventMatchingListInMode ()
#7  0x00007fff86378eb2 in _DPSNextEvent ()
#8  0x00007fff86378801 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#9  0x00007fff8633e68f in -[NSApplication run] ()
#10 0x000000010019ac26 in ns_select (nfds=<value temporarily unavailable, due to optimizations>, readfds=0x7fff5fbfdca0, writefds=0x7fff5fbfdc20, exceptfds=<value temporarily unavailable, due to optimizations>, timeout=0x7fff5fbfdd40, sigmask=<value temporarily unavailable, due to optimizations>) at nsterm.m:3573
#11 0x000000010016a27d in wait_reading_process_output (time_limit=<value temporarily unavailable, due to optimizations>, nsecs=0, read_kbd=-1, do_display=1, wait_for_cell=4320145466, wait_proc=0x0, just_wait_proc=0) at process.c:4680
#12 0x00000001000b6bf6 in read_char (commandflag=1, nmaps=2, maps=0x7fff5fbfe190, prev_event=<value temporarily unavailable, due to optimizations>, used_mouse_menu=0x7fff5fbfe3b4, end_time=0x0) at keyboard.c:3915
#13 0x00000001000b8ca5 in read_key_sequence (keybuf=0x7fff5fbfe470, bufsize=30, prompt=4320145466, dont_downcase_last=0, can_return_switch_frame=1, fix_current_buffer=1) at keyboard.c:9372
#14 0x00000001000bb0ae in command_loop_1 () at keyboard.c:1510
#15 0x0000000100122605 in internal_condition_case (bfun=0x1000bae50 <command_loop_1>, handlers=4320212330, hfun=0x1000b1580 <cmd_error>) at eval.c:1322
#16 0x00000001000af137 in command_loop_2 (ignore=<value temporarily unavailable, due to optimizations>) at keyboard.c:1204
#17 0x000000010012270b in internal_catch (tag=<value temporarily unavailable, due to optimizations>, func=0x1000af100 <command_loop_2>, arg=4320145466) at eval.c:1079
#18 0x00000001000af7ac in recursive_edit_1 () at keyboard.c:1183
#19 0x00000001000af91b in Frecursive_edit () at keyboard.c:868
#20 0x00000001000a8df0 in main (argc=2, argv=0x7fff5fbfea48) at emacs.c:1662

In GNU Emacs 24.2.50.2 (i386-apple-darwin10.8.0, NS apple-appkit-1038.36)
of 2012-08-20 on oroszlan.local
Bzr revision: 109700 [email-masked]
Windowing system distributor `Apple', version 10.3.1038
Configured using:
`configure '--with-ns''

Important settings:
  value of $LC_CTYPE: UTF-8
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
<help-echo> M-x r e p o <tab> r <tab> <return>

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Making completion list...

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util
mail-prsvr mail-utils help-mode easymenu time-date tooltip ediff-hook
vc-hooks lisp-float-type mwheel ns-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list newcomment lisp-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core frame cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer loaddefs
button faces cus-face files text-properties overlay sha1 md5 base64
format env code-pages mule custom widget hashtable-print-readable
backquote make-network-process ns multi-tty emacs)