From f9da45df47270c1f58736e78bc4f6716e1828e40 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Wed, 6 Apr 2022 17:17:41 +0800 Subject: [PATCH] Prevent races when trying to set Motif drag window * src/xterm.c (xm_get_drag_window): Grab temp connection when setting the drag window. --- src/xterm.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/xterm.c b/src/xterm.c index 7eef2b488be..b6aed004ed3 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -1395,13 +1395,18 @@ xm_get_drag_window (struct x_display_info *dpyinfo) if (drag_window == None) { + block_input (); unrequest_sigio (); temp_display = XOpenDisplay (XDisplayString (dpyinfo->display)); request_sigio (); if (!temp_display) - return None; + { + unblock_input (); + return None; + } + XGrabServer (temp_display); XSetCloseDownMode (temp_display, RetainPermanent); attrs.override_redirect = True; drag_window = XCreateWindow (temp_display, DefaultRootWindow (temp_display), @@ -1422,6 +1427,7 @@ xm_get_drag_window (struct x_display_info *dpyinfo) drag_window, &wattrs); rc = !x_had_errors_p (dpyinfo->display); x_uncatch_errors_after_check (); + unblock_input (); /* We connected to the wrong display, so just give up. */ if (!rc) -- 2.39.5