Emacs hangs occasionally due to malloc calls in signal handler
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
emacs21 (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
Binary package hint: emacs21
I have experienced occasional hangs in Emacs for some time now. This has prompted me to compile Emacs with debug symbols to be able to track it down, and just now I managed to capture a hang shortly after startup in gdb. The backtrace shows a deadlock in a malloc mutex due to mallopt() being called from a signal handler that has interrupted an earlier mallopt() call:
(gdb) bt
#0 0x00007fcb51e1c24e in __lll_lock_
#1 0x00007fcb51db0500 in _L_lock_3213 () from /lib/libc.so.6
#2 0x00007fcb51daadd5 in mallopt () from /lib/libc.so.6
#3 0x00000000005579ab in emacs_blocked_
at /usr/local/
#4 0x00007fcb517245a9 in ?? () from /usr/lib/
#5 0x00007fcb51724aa7 in xcb_poll_for_event () from /usr/lib/
#6 0x00007fcb5231cd75 in ?? () from /usr/lib/
#7 0x00007fcb5231d426 in _XEventsQueued () from /usr/lib/
#8 0x00007fcb52306fcd in XPending () from /usr/lib/
#9 0x00000000004b5bbf in XTread_socket (sd=1376344544, bufp=0x7fff5c41
numchars=4096, expected=1)
at /usr/local/
#10 0x00000000004f10ca in read_avail_input (expected=1)
at /usr/local/
#11 0x00000000004f13ee in input_available
at /usr/local/
#12 <signal handler called>
#13 0x00007fcb51daa2b6 in malloc_consolidate () from /lib/libc.so.6
#14 0x00007fcb51daade1 in mallopt () from /lib/libc.so.6
#15 0x000000000055962e in allocate_vectorlike (len=5, type=MEM_
at /usr/local/
#16 0x00000000005596f1 in allocate_vector (nslots=5)
at /usr/local/
I have verified that __lll_lock_
Judging from the libc documentation regarding Signal Handling and Nonreentrant Functions (24.4.6), I believe the bug is that Emacs does rather too much work from within a signal handler.
I'm using hardy and emacs21 21.4a+1-
The problem is that the signal handler isn't blocked in the mallopt() calls. The attached patch fixes it. The patch is based on the fix made in emacs 22, and I've also looked through the sources for mallopt() calls and DOUG_LEA_MALLOC code to ensure all instances are fixed.