From ae0ec1eede3dac8ae82c3a82d7d7f6b956d8db24 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Sun, 30 Oct 2022 13:13:28 +0800 Subject: [PATCH] Plug big leaks upon display IO error Frame GCs are still leaked, but there is nothing that can be done in that case because the display connection is dead. * src/xterm.c (x_delete_terminal): Always free xkb desc and modmap. --- src/xterm.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/xterm.c b/src/xterm.c index f1bccddb6c3..7dd969b821f 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -30277,11 +30277,6 @@ x_delete_terminal (struct terminal *terminal) closing all the displays. */ XrmDestroyDatabase (dpyinfo->rdb); #endif - -#ifdef HAVE_XKB - if (dpyinfo->xkb_desc) - XkbFreeKeyboard (dpyinfo->xkb_desc, XkbAllComponentsMask, True); -#endif #ifdef USE_GTK xg_display_close (dpyinfo->display); #else @@ -30291,9 +30286,6 @@ x_delete_terminal (struct terminal *terminal) XCloseDisplay (dpyinfo->display); #endif #endif /* ! USE_GTK */ - - if (dpyinfo->modmap) - XFreeModifiermap (dpyinfo->modmap); /* Do not close the connection here because it's already closed by X(t)CloseDisplay (Bug#18403). */ dpyinfo->display = NULL; @@ -30306,6 +30298,18 @@ x_delete_terminal (struct terminal *terminal) else if (dpyinfo->connection >= 0) emacs_close (dpyinfo->connection); + /* Free the keyboard and modifier maps here; that is safe to do + without a display, and not doing so leads to a lot of data being + leaked upon IO error. */ + +#ifdef HAVE_XKB + if (dpyinfo->xkb_desc) + XkbFreeKeyboard (dpyinfo->xkb_desc, XkbAllComponentsMask, True); +#endif + + if (dpyinfo->modmap) + XFreeModifiermap (dpyinfo->modmap); + /* No more input on this descriptor. */ delete_keyboard_wait_descriptor (dpyinfo->connection); /* Mark as dead. */ -- 2.39.5