From 80465f41d7fc67d40f0a233504e295b127ad2c6b Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Tue, 9 Sep 2014 07:22:36 +0400 Subject: [PATCH] * xterm.c (x_term_init): Consolidate duplicated code. [USE_LUCID]: Revert 2014-04-02 change (Bug#18403). Add comment. (x_delete_terminal): Do not close X connection fd (Bug#18403). Add eassert and mark dpyinfo as dead only if it was alive. --- src/ChangeLog | 7 +++++++ src/xterm.c | 33 ++++++++++++++------------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 4e01e155c2e..a01c753161c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2014-09-09 Dmitry Antipov + + * xterm.c (x_term_init): Consolidate duplicated code. + [USE_LUCID]: Revert 2014-04-02 change (Bug#18403). Add comment. + (x_delete_terminal): Do not close X connection fd (Bug#18403). + Add eassert and mark dpyinfo as dead only if it was alive. + 2014-09-08 Eli Zaretskii * dispnew.c (prepare_desired_row): When MODE_LINE_P is zero, diff --git a/src/xterm.c b/src/xterm.c index 767de9786cb..6ff33785a38 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -10667,7 +10667,6 @@ static unsigned x_display_id; struct x_display_info * x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) { - int connection; Display *dpy; struct terminal *terminal; struct x_display_info *dpyinfo; @@ -11110,22 +11109,19 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) xsettings_initialize (dpyinfo); - connection = ConnectionNumber (dpyinfo->display); - /* This is only needed for distinguishing keyboard and process input. */ - if (connection != 0) - add_keyboard_wait_descriptor (connection); + if (dpyinfo->connection != 0) + add_keyboard_wait_descriptor (dpyinfo->connection); #ifdef F_SETOWN - fcntl (connection, F_SETOWN, getpid ()); + fcntl (dpyinfo->connection, F_SETOWN, getpid ()); #endif /* ! defined (F_SETOWN) */ if (interrupt_input) - init_sigio (connection); + init_sigio (dpyinfo->connection); #ifdef USE_LUCID { - XFontStruct *xfont = NULL; XrmValue d, fr, to; Font font; @@ -11139,10 +11135,10 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) x_catch_errors (dpy); if (!XtCallConverter (dpy, XtCvtStringToFont, &d, 1, &fr, &to, NULL)) emacs_abort (); - if (x_had_errors_p (dpy) || !((xfont = XQueryFont (dpy, font)))) + if (x_had_errors_p (dpy) || !XQueryFont (dpy, font)) XrmPutLineResource (&xrdb, "Emacs.dialog.*.font: 9x15"); - if (xfont) - XFreeFont (dpy, xfont); + /* Do not free XFontStruct returned by the above call to XQueryFont. + This leads to X protocol errors at XtCloseDisplay (Bug#18403). */ x_uncatch_errors (); } #endif @@ -11375,18 +11371,17 @@ x_delete_terminal (struct terminal *terminal) XCloseDisplay (dpyinfo->display); #endif #endif /* ! USE_GTK */ - } - /* No more input on this descriptor. */ - if (0 <= dpyinfo->connection) - { + /* No more input on this descriptor. Do not close it because + it's already closed by X(t)CloseDisplay (Bug#18403). */ + eassert (0 <= dpyinfo->connection); delete_keyboard_wait_descriptor (dpyinfo->connection); - emacs_close (dpyinfo->connection); + + /* Mark as dead. */ + dpyinfo->display = NULL; + dpyinfo->connection = -1; } - /* Mark as dead. */ - dpyinfo->display = NULL; - dpyinfo->connection = -1; x_delete_display (dpyinfo); unblock_input (); } -- 2.39.5