Subject: Re: bug#26493: 26.0.50; Segmentation fault while scrolling if emacs does not have focus

From: martin rudalics <[email-masked]>
Date: Fri, 14 Apr 2017 11:45:43 +0200

> I have a segmentation fault if I try to scroll when Emacs does not have the
 > focus. I use openbox as window manager.
 >
 >
 > Start emacs -Q
 > Move mouse pointer above the Emacs windows.
 > Use alt-tab to give the focus to another program
 > Use mouse scroll wheel (still above Emacs window).
 > => segmentation fault
 >
 >
 > Full backtrace:
 >
 > #0  0x00000000004261e3 in frame_ancestor_p (af=0x140fc30 <bss_sbrk_buffer+7475472>, df=0x0)
 >      at frame.c:1372
 >          pf = 0x7fffffffc200
 > #1  0x000000000052cd25 in handle_one_xevent (dpyinfo=0x2d51ae0, event=0x7fffffffca10, finish=0x7fffffffca00, hold_quit=0x7fffffffcb30) at xterm.c:8804
 >          hf = 0x0
 >          tool_bar_p = false
 >          inev =
 >              {kind = NO_EVENT, ie = {kind = NO_EVENT, part = scroll_bar_nowhere, code = 0, modifiers = 0, x = 0, y = 0, timestamp = 0, frame_or_window = 0, arg = 0}, sie = {kind = NO_EVENT, dpyinfo = 0x0, requestor = 0, selection = 0, target = 0, property = 0, time = 0}}
 >          count = 0
 >          do_help = 0
 >          nbytes = 0
 >          any = 0x140fc30 <bss_sbrk_buffer+7475472>
 >          f = 0x140fc30 <bss_sbrk_buffer+7475472>
 >          coding =
 >            {id = -1, common_flags = 16383, mode = 31, src_multibyte = true, dst_multibyte = true, chars_at_source = true, raw_destination = true, annotated = true, eol_seen = 7, result = 7, max_charset_id = -1, spec = {iso_2022 = {flags = 0, current_invocation = {-1, -1}, current_designation = {-1, 0, 0, 0}, ctext_extended_segment_len = 50176, single_shifting = false, bol = true, embedded_utf_8 = false, cmp_status = {state = COMPOSING_NO, method = 66, old_form = false, length = -1, nchars = -1, ncomps = -1, carryover = {0, 66, 0, 66, 0, 134668801, 2072141089, 50452993, 134667042, -1, 16711680, 16711680, 0, 32, 0, 0, 0, -1, -1, 255, 0 <repeats 17 times>, 135, 0, 4096, 1, 80, 0, 11231104, 0, 8, 0, -14976, 32767, 1179670611, 1092, 31, 0, 1088, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0}}}, ccl = 0xffffffff00000000, utf_16 = {bom = utf_detect_bom, endian = (utf_16_little_endian | unknown: 4294967294), surrogate = -1}, utf_8_bom = utf_detect_bom, emacs_mule = {cmp_status = {state = COMP
OSING_NO, method = 4294967295, old_form = 255, length = -1, nchars = 0, ncomps = 0, carryover = {0, 50176, 66, 0, 66, 0, -1, -1, -1, 0, 66, 0, 66, 0, 134668801, 2072141089, 50452993, 134667042, -1, 16711680, 16711680, 0, 32, 0, 0, 0, -1, -1, 255, 0 <repeats 17 times>, 135, 0, 4096, 1, 80, 0, 11231104, 0, 8, 0, -14976, 32767, 1179670611, 1092, 31, 0, 1088, 0, 0, 0, 0, 0}}}, undecided = {inhibit_nbd = 0, inhibit_ied = -1, prefer_utf_8 = 255}}, safe_charsets = 0x0, head_ascii = 0, detected_utf8_bytes = 0, detected_utf8_chars = 0, produced = 0, produced_char = 0, consumed = 0, consumed_char = 0, 
src_pos = 0, src_pos_byte = 0, src_chars = 0, src_bytes = 0, src_object = 0, source = 0x0, dst_pos = 0, dst_pos_byte = 0, dst_bytes = 0, dst_object = 0, destination = 0x10 <error: Cannot access memory at address 0x10>, charbuf = 0x0, charbuf_size = 0, charbuf_used = 0, carryover = '\000' <repeats 32 times>, "\257\351\340\365\377\177\000\000\020\340\332\002", '\000' <repeats 19 times>, carryover_bytes = -259085600, default_char = 32767, detector = 0x10, decoder = 0xb838ff3405eea000, encoder = 0x0}
 >          hlinfo = 0x2d51b90
 >          compose_status = {compose_ptr = 0x0, chars_matched = 0}
 >          configureEvent =
 >              {type = 5602335, xany = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, window = 7208293045859083529}, xkey = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, window = 7208293045859083529, root = 0, subwindow = 9665507694643000451, time = 2363011884663504947, x = 471566794, y = -842261046, x_root = 97570766, y_root = -769470175, state = 164859428, keycode = 2284049508, same_screen = 1680443436}, xbutton = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, window = 7208293045859083529, root = 0, subwindow = 9665507694643000451, time = 2363011884663504947, x = 471566794, y = -842261046, x_root = 97570766, y_root = -769470175, state = 164859428, button = 2284049508, same_screen = 1680443436}, xmotion = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, window =
 7208293045859083529, root = 0, subwindow = 9665507694643000451, time = 2363011884663504947, x = 471566794, y = -842261046, x_root = 97570766, y_root = -769470175, state = 164859428, is_hint = 100 'd', same_screen = 1680443436}, xcrossing = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, window = 7208293045859083529, root = 0, subwindow = 9665507694643000451, time = 2363011884663504947, x = 471566794, y = -842261046, x_root = 97570766, y_root = -769470175, mode = 164859428, detail = -2010917788, same_screen = 1680443436, focus = 19474705, 
state = 2189604417}, xfocus = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, window = 7208293045859083529, mode = 0, detail = 0}, xexpose = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, window = 7208293045859083529, x = 0, y = 0, width = -922733437, height = -2044540919, count = 291831859}, xgraphicsexpose = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, drawable = 7208293045859083529, x = 0, y = 0, width = -922733437, height = -2044540919, count = 291831859, major_code = 550181578, minor_code = 471566794}, xnoexpose = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, drawable = 7208293045859083529, major_code = 0, minor_code = 0}, xvisibility = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, window = 720829304
5859083529, state = 0}, xcreatewindow = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, parent = 7208293045859083529, window = 0, x = -922733437, y = -2044540919, width = 291831859, height = 550181578, border_width = 471566794, override_redirect = -842261046}, xdestroywindow = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, event = 7208293045859083529, window = 0}, xunmap = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, event = 
7208293045859083529, window = 0, from_configure = -922733437}, xmap = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, event = 7208293045859083529, window = 0, override_redirect = -922733437}, xmaprequest = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, parent = 7208293045859083529, window = 0}, xreparent = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, event = 7208293045859083529, window = 0, parent = 9665507694643000451, x = 291831859, y = 550181578, override_redirect = 471566794}, xconfigure = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, event = 7208293045859083529, window = 0, x = -922733437, y = -2044540919, width = 291831859, height = 550181578, border_width = 471566794, above = 15141894836934725582, override_redirect = 164859428}, xgravity = {type = 560233
5, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, event = 7208293045859083529, window = 0, x = -922733437, y = -2044540919}, xresizerequest = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, window = 7208293045859083529, width = 0, height = 0}, xconfigurerequest = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, parent = 7208293045859083529, window = 0, x = -922733437, y = -2044540919, width = 291831859, height = 550181578, border_width = 471566794, 
above = 15141894836934725582, detail = 164859428, value_mask = 83643222754691116}, xcirculate = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, event = 7208293045859083529, window = 0, place = -922733437}, xcirculaterequest = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, parent = 7208293045859083529, window = 0, place = -922733437}, xproperty = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, window = 7208293045859083529, atom = 0, time = 9665507694643000451, state = 291831859}, xselectionclear = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, window = 7208293045859083529, selection = 0, time = 9665507694643000451}, xselectionrequest = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, owner = 7208293045859083529, 
requestor = 0, selection = 9665507694643000451, target = 2363011884663504947, property = 14829260426916366794, time = 15141894836934725582}, xselection = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, requestor = 7208293045859083529, selection = 0, target = 9665507694643000451, property = 2363011884663504947, time = 14829260426916366794}, xcolormap = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, window = 7208293045859083529, colormap = 0, new = -922733437, state = -2044540919}, xclient 
= {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, window = 7208293045859083529, message_type = 0, format = -922733437, data = {b = "3\000e\021\312\032\313 ʉ\033\034\312\035\314\315\316\317\320\005", s = {51, 4453, 6858, 8395, -30262, 7195, 7626, -12852, -12338, 1488}, l = {2363011884663504947, -3617483646793184822, -3304849236774826034, -8636826134239801820, 83643222754691116}}}, xmapping = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, window = 7208293045859083529, request = 0, first_keycode = 0, count = -922733437}, xerror = {type = 5602335, display = 0x8920c60060853f08, resourceid = 8181195819597192837, serial = 9835452569303058824, error_code = 9 '\t', request_code = 101 'e', minor_code = 89 'Y'}, xkeymap = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, window = 7208293045859083529, key_vector = "\000\000\000\000\
000\000\000\000\203\064\000\311\t\310\"\206\063\000e\021\312\032\313 ʉ\033\034\312\035\314", <incomplete sequence \315>}, xgeneric = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, extension = -2091293431, evtype = 1678311509}, xcookie = {type = 5602335, serial = 9881115287372513032, send_event = -1996464507, display = 0x887e8c0056830988, extension = -2091293431, evtype = 1678311509, cookie = 0, data = 0x8622c809c9003483}, pad = {5602335, -8565628786337038584, 8181195819597192837, -8611291504406492792, 7208293045859083529, 0, 
-8781236379066551165, 2363011884663504947, -3617483646793184822, -3304849236774826034, -8636826134239801820, 83643222754691116, 122160172146800193, 11182983, 140737488340864, 6626252, 140737488341584, 0, 2, 42, 11182869, 11182836, 11230669, 7696581394474}}
 >          next_event =
 >              {type = 895, xany = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, window = 0}, xkey = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, window = 0, root = 0, subwindow = 0, time = 0, x = 0, y = 0, x_root = 0, y_root = 0, state = 0, keycode = 0, same_screen = 0}, xbutton = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, window = 0, root = 0, subwindow = 0, time = 0, x = 0, y = 0, x_root = 0, y_root = 0, state = 0, button = 0, same_screen = 0}, xmotion = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, window = 0, root = 0, subwindow = 0, time = 0, x = 0, y = 0, x_root = 0, y_root = 0, state = 0, is_hint = 0 '\000', same_screen = 0}, xcrossing = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, window = 0, root = 0, subwindow = 0, time = 0, x = 0, y = 0, x_root = 0, y_root = 0, mode = 0, detail = 0, same_screen = 0, focus = 0, state = 0}, xfocus = {
type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, window = 0, mode = 0, detail = 0}, xexpose = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, window = 0, x = 0, y = 0, width = 0, height = 0, count = 0}, xgraphicsexpose = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, drawable = 0, x = 0, y = 0, width = 0, height = 0, count = 0, major_code = 0, minor_code = 0}, xnoexpose = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, drawable = 0, major_code = 0, minor_code = 0}, xvisibility = {type = 895, serial 
= 6252629, send_event = 0, display = 0xffff00001fa0, window = 0, state = 0}, xcreatewindow = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, parent = 0, window = 0, x = 0, y = 0, width = 0, height = 0, border_width = 0, override_redirect = 0}, xdestroywindow = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, event = 0, window = 0}, xunmap = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, event = 0, window = 0, from_configure = 0}, xmap = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, event = 0, window = 0, override_redirect = 0}, xmaprequest = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, parent = 0, window = 0}, xreparent = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, event = 0, window = 0, parent = 0, x = 0, y = 0, override_redirect = 0}, xconfigure = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, event
 = 0, window = 0, x = 0, y = 0, width = 0, height = 0, border_width = 0, above = 0, override_redirect = 0}, xgravity = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, event = 0, window = 0, x = 0, y = 0}, xresizerequest = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, window = 0, width = 0, height = 0}, xconfigurerequest = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, parent = 0, window = 0, x = 0, y = 0, width = 0, height = 0, border_width = 0, above = 0, detail = 0, value_mask = 0}, xcirculate = {type = 895, serial = 
6252629, send_event = 0, display = 0xffff00001fa0, event = 0, window = 0, place = 0}, xcirculaterequest = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, parent = 0, window = 0, place = 0}, xproperty = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, window = 0, atom = 0, time = 0, state = 0}, xselectionclear = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, window = 0, selection = 0, time = 0}, xselectionrequest = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, owner = 0, requestor = 0, selection = 0, target = 0, property = 0, time = 0}, xselection = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, requestor = 0, selection = 0, target = 0, property = 0, time = 0}, xcolormap = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, window = 0, colormap = 0, new = 0, state = 0}, xclient = {type = 895, serial = 6252629, send_event = 0, display = 0
xffff00001fa0, window = 0, message_type = 0, format = 0, data = {b = '\000' <repeats 19 times>, s = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, l = {0, 0, 0, 0, 0}}}, xmapping = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, window = 0, request = 0, first_keycode = 0, count = 0}, xerror = {type = 895, display = 0x5f6855 <decode_float_time+241>, resourceid = 0, serial = 281470681751456, error_code = 0 '\000', request_code = 0 '\000', minor_code = 0 '\000'}, xkeymap = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, window = 0, key_vector = '\000' <repeats 31 
times>}, xgeneric = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, extension = 0, evtype = 0}, xcookie = {type = 895, serial = 6252629, send_event = 0, display = 0xffff00001fa0, extension = 0, evtype = 0, cookie = 0, data = 0x0}, pad = {895, 6252629, 0, 281470681751456, 0 <repeats 12 times>, -1669528073709551616, 16422, -1669528073709551616, 16421, 0, 0, 4294967296, 4294967296}}
 >          sa_avail = 16384
 >          sa_count = 4
 >          sa_must_free = false

Thanks for the report (I cannot reproduce it here but the cause seems
obvious).  Would the attached patch fix it?

martin
diff --git a/src/xterm.c b/src/xterm.c
index 8dc1067..5169292 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -8801,7 +8801,7 @@ static void xembed_send_message (struct frame *f, Time,
 		   frame.  */
 		struct frame *hf = dpyinfo->x_highlight_frame;
 
-		if (FRAME_PARENT_FRAME (f) || frame_ancestor_p (f, hf))
+		if (FRAME_PARENT_FRAME (f) || (hf && frame_ancestor_p (f, hf)))
 		  {
 		    block_input ();
 		    XSetInputFocus (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),