(x_delete_terminal): Call xim_close_dpy.
#ifndef AIX /* On AIX, XCloseDisplay calls this. */
XrmDestroyDatabase (dpyinfo->xrdb);
#endif
-#endif
-#ifdef HAVE_X_I18N
- if (dpyinfo->xim)
- xim_close_dpy (dpyinfo);
#endif
xfree (dpyinfo->x_id_name);
return;
BLOCK_INPUT;
+#ifdef HAVE_X_I18N
+ /* We must close our connection to the XIM server before closing the
+ X display. */
+ if (dpyinfo->xim)
+ xim_close_dpy (dpyinfo);
+#endif
+
/* If called from x_connection_closed, the display may already be closed
and dpyinfo->display was set to 0 to indicate that. */
if (dpyinfo->display)