emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master eb68c3d5a2 1/2: Fix leak on Lucid build


From: Po Lu
Subject: master eb68c3d5a2 1/2: Fix leak on Lucid build
Date: Tue, 1 Nov 2022 07:20:26 -0400 (EDT)

branch: master
commit eb68c3d5a23e519a4b9ffc7b87fa7db68a18ae0b
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Fix leak on Lucid build
    
    * src/xterm.c (x_term_init): Rectify wrong fix for bug#18403.
---
 src/xterm.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/xterm.c b/src/xterm.c
index 7dd969b821..d8358269f6 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -29778,21 +29778,30 @@ x_term_init (Lisp_Object display_name, char 
*xrm_option, char *resource_name)
   {
     XrmValue d, fr, to;
     Font font;
+    XFontStruct *query_result;
 
     dpy = dpyinfo->display;
-    d.addr = (XPointer)&dpy;
+    d.addr = (XPointer) &dpy;
     d.size = sizeof (Display *);
     fr.addr = (char *) XtDefaultFont;
     fr.size = sizeof (XtDefaultFont);
     to.size = sizeof (Font *);
-    to.addr = (XPointer)&font;
+    to.addr = (XPointer) &font;
     x_catch_errors (dpy);
     if (!XtCallConverter (dpy, XtCvtStringToFont, &d, 1, &fr, &to, NULL))
       emacs_abort ();
-    if (x_had_errors_p (dpy) || !XQueryFont (dpy, font))
+    query_result = XQueryFont (dpy, font);
+
+    /* Set the dialog font to some fallback (here, 9x15) if the font
+       specified is invalid.  */
+    if (x_had_errors_p (dpy) || !font)
       XrmPutLineResource (&xrdb, "Emacs.dialog.*.font: 9x15");
-    /* Do not free XFontStruct returned by the above call to XQueryFont.
-       This leads to X protocol errors at XtCloseDisplay (Bug#18403).  */
+
+    /* Do not destroy the font struct returned above with XFreeFont;
+       that also destroys the font, leading to to X protocol errors at
+       XtCloseDisplay.  Just free the font info structure.
+       (Bug#18403) */
+    XFreeFontInfo (NULL, query_result, 0);
     x_uncatch_errors ();
   }
 #endif



reply via email to

[Prev in Thread] Current Thread [Next in Thread]