+2014-09-09 Dmitry Antipov <dmantipov@yandex.ru>
+
+ * 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 <eliz@gnu.org>
* dispnew.c (prepare_desired_row): When MODE_LINE_P is zero,
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;
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;
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
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 ();
}