all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#16069: emacs bug #16069 - cause & reproduction
       [not found] <1393504047.11841.YahooMailNeo@web125304.mail.ne1.yahoo.com>
@ 2014-02-28  6:39 ` Dmitry Antipov
  2014-03-01 10:36   ` nil
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Antipov @ 2014-02-28  6:39 UTC (permalink / raw)
  To: nil; +Cc: 16069

[-- Attachment #1: Type: text/plain, Size: 1261 bytes --]

On 02/27/2014 04:27 PM, nil wrote:

> I ran into the first crash reported on bug #16069, on trunk r116550. It appears to trigger when an xftfont is garbage collected - but only after its Display has been freed and then reused. The guard in xftfont_close is satisfied, then XftFontClose causes xft's reference counting to go out of sync. SIGSEGV occurs when the display is closed (_XftCloseDisplay, XftFontManageMemory, XftFontFindNthUnref returns an unexpected NULL)
>
> To reproduce:
>
> gdb --args emacs -Q -nw
>
> set $dpy = 0
> break xterm.c:9810
>    condition $bpnum $dpy == dpy
> break xterm.c:9814
>    commands
>      silent
>      set $dpy = dpy
>      cont
>    end
> run
>
> M-x server-start
>
> Then repeatedly:
>
> emacsclient -c -n .
> C-x C-c
>
> until the breakpoint fires on Display address reuse. after continuing, closing the terminal should SIGSEGV in xft/src/xftfreetype.c. (This is on an x86_64 linux with recent glibc/xorg/etc, if it makes any difference.)
>
> I'm not nearly familiar enough with the insides of emacs to suggest a fix, I'm afraid. Happy to provide any other information you need, though!

Thanks. Next time please do CC: to appropriate bug (i.e. [bug-number]@debbugs.gnu.org).

Could you please try this patch?

Dmitry


[-- Attachment #2: x_display_id.patch --]
[-- Type: text/x-patch, Size: 3452 bytes --]

=== modified file 'src/xfont.c'
--- src/xfont.c	2014-01-01 07:43:34 +0000
+++ src/xfont.c	2014-02-28 06:20:04 +0000
@@ -42,6 +42,7 @@
   struct font font;
   Display *display;
   XFontStruct *xfont;
+  unsigned x_display_id;
 };
 
 /* Prototypes of support functions.  */
@@ -808,6 +809,7 @@
   font = XFONT_OBJECT (font_object);
   ((struct xfont_info *) font)->xfont = xfont;
   ((struct xfont_info *) font)->display = FRAME_X_DISPLAY (f);
+  ((struct xfont_info *) font)->x_display_id = FRAME_DISPLAY_INFO (f)->x_id;
   font->pixel_size = pixel_size;
   font->driver = &xfont_driver;
   font->encoding_charset = encoding->id;
@@ -892,12 +894,15 @@
 static void
 xfont_close (struct font *font)
 {
+  struct x_display_info *xdi;
   struct xfont_info *xfi = (struct xfont_info *) font;
 
   /* This function may be called from GC when X connection is gone
      (Bug#16093), and an attempt to free font resources on invalid
      display may lead to X protocol errors or segfaults.  */
-  if (xfi->xfont && x_display_info_for_display (xfi->display))
+  if (xfi->xfont
+      && ((xdi = x_display_info_for_display (xfi->display))
+	  && xfi->x_display_id == xdi->x_id))
     {
       block_input ();
       XFreeFont (xfi->display, xfi->xfont);

=== modified file 'src/xftfont.c'
--- src/xftfont.c	2014-01-06 06:25:30 +0000
+++ src/xftfont.c	2014-02-28 06:23:32 +0000
@@ -59,6 +59,7 @@
   FT_Matrix matrix;
   Display *display;
   XftFont *xftfont;
+  unsigned x_display_id;
 };
 
 /* Structure pointed by (struct face *)->extra  */
@@ -372,6 +373,7 @@
   xftfont_info = (struct xftfont_info *) font;
   xftfont_info->display = display;
   xftfont_info->xftfont = xftfont;
+  xftfont_info->x_display_id = FRAME_DISPLAY_INFO (f)->x_id;
   /* This means that there's no need of transformation.  */
   xftfont_info->matrix.xx = 0;
   if (FcPatternGetMatrix (xftfont->pattern, FC_MATRIX, 0, &matrix)
@@ -481,6 +483,7 @@
 static void
 xftfont_close (struct font *font)
 {
+  struct x_display_info *xdi;
   struct xftfont_info *xftfont_info = (struct xftfont_info *) font;
 
 #ifdef HAVE_LIBOTF
@@ -493,7 +496,8 @@
 
   /* See comment in xfont_close.  */
   if (xftfont_info->xftfont
-      && x_display_info_for_display (xftfont_info->display))
+      && ((xdi = x_display_info_for_display (xftfont_info->display))
+	  && xftfont_info->x_display_id == xdi->x_id))
     {
       block_input ();
       XftUnlockFace (xftfont_info->xftfont);

=== modified file 'src/xterm.c'
--- src/xterm.c	2014-02-04 07:36:58 +0000
+++ src/xterm.c	2014-02-28 06:28:46 +0000
@@ -9679,6 +9679,8 @@
 }
 #endif
 
+static unsigned x_display_id;
+
 /* Open a connection to X display DISPLAY_NAME, and return
    the structure that describes the open display.
    If we cannot contact the display, return null.  */
@@ -9896,6 +9898,7 @@
   lim = min (PTRDIFF_MAX, SIZE_MAX) - sizeof "@";
   if (lim - SBYTES (Vinvocation_name) < SBYTES (Vsystem_name))
     memory_full (SIZE_MAX);
+  dpyinfo->x_id = ++x_display_id;
   dpyinfo->x_id_name = xmalloc (SBYTES (Vinvocation_name)
 				+ SBYTES (Vsystem_name) + 2);
   strcat (strcat (strcpy (dpyinfo->x_id_name, SSDATA (Vinvocation_name)), "@"),

=== modified file 'src/xterm.h'
--- src/xterm.h	2014-01-11 09:31:09 +0000
+++ src/xterm.h	2014-02-28 06:11:05 +0000
@@ -198,6 +198,7 @@
      mouse-face.  */
   Mouse_HLInfo mouse_highlight;
 
+  unsigned x_id;
   char *x_id_name;
 
   /* The number of fonts opened for this display.  */


^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#16069: emacs bug #16069 - cause & reproduction
  2014-02-28  6:39 ` bug#16069: emacs bug #16069 - cause & reproduction Dmitry Antipov
@ 2014-03-01 10:36   ` nil
  2014-03-03 10:53     ` Dmitry Antipov
  0 siblings, 1 reply; 5+ messages in thread
From: nil @ 2014-03-01 10:36 UTC (permalink / raw)
  To: Dmitry Antipov; +Cc: 16069@debbugs.gnu.org

[-- Attachment #1: Type: text/plain, Size: 273 bytes --]

Sorry, shall do.

Xft fonts will be leaked, but that patch does appear to solve the crash; thanks!

(while poking around in font.c I noticed the font cache wasn't being cleared due to a change of structure, something along the lines of the attached seemed to fix it.)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: font_clear_cache.patch --]
[-- Type: text/x-diff; name="font_clear_cache.patch", Size: 994 bytes --]

diff --git i/src/font.c w/src/font.c
index 8027de8..5aada83 100644
--- i/src/font.c
+++ w/src/font.c
@@ -2585,18 +2585,21 @@ static void
 font_clear_cache (struct frame *f, Lisp_Object cache, struct font_driver *driver)
 {
   Lisp_Object tail, elt;
-  Lisp_Object tail2, entity;
+  Lisp_Object entity;
+  int i;
 
   /* CACHE = (DRIVER-TYPE NUM-FRAMES FONT-CACHE-DATA ...) */
   for (tail = XCDR (XCDR (cache)); CONSP (tail); tail = XCDR (tail))
     {
       elt = XCAR (tail);
-      /* elt should have the form (FONT-SPEC FONT-ENTITY ...) */
+      /* elt should have the form (FONT-SPEC . [ FONT-ENTITY ...]) */
       if (CONSP (elt) && FONT_SPEC_P (XCAR (elt)))
 	{
-	  for (tail2 = XCDR (elt); CONSP (tail2); tail2 = XCDR (tail2))
+	  elt = XCDR (elt);
+	  eassert (VECTORP (elt));
+	  for (i = 0; i < ASIZE (elt); i++)
 	    {
-	      entity = XCAR (tail2);
+	      entity = AREF (elt, i);
 
 	      if (FONT_ENTITY_P (entity)
 		  && EQ (driver->type, AREF (entity, FONT_TYPE_INDEX)))

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#16069: emacs bug #16069 - cause & reproduction
  2014-03-01 10:36   ` nil
@ 2014-03-03 10:53     ` Dmitry Antipov
  2014-03-03 16:50       ` Glenn Morris
  2018-06-07  0:03       ` bug#16069: Sigsegv, libxft, emacs --daemon, emacsclient Noam Postavsky
  0 siblings, 2 replies; 5+ messages in thread
From: Dmitry Antipov @ 2014-03-03 10:53 UTC (permalink / raw)
  To: nil; +Cc: 16069@debbugs.gnu.org

On 03/01/2014 02:36 PM, nil wrote:

> Xft fonts will be leaked

Yes - if GC happens at arbitrary point after X connection is gone, there
is no way to release font-related resources.  Anyway, better than crash.
Installed in r116642.

> (while poking around in font.c I noticed the font cache wasn't being cleared due
> to a change of structure, something along the lines of the attached seemed to fix it.)

Thanks, installed in r116641.

Dmitry






^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#16069: emacs bug #16069 - cause & reproduction
  2014-03-03 10:53     ` Dmitry Antipov
@ 2014-03-03 16:50       ` Glenn Morris
  2018-06-07  0:03       ` bug#16069: Sigsegv, libxft, emacs --daemon, emacsclient Noam Postavsky
  1 sibling, 0 replies; 5+ messages in thread
From: Glenn Morris @ 2014-03-03 16:50 UTC (permalink / raw)
  To: Dmitry Antipov; +Cc: 16069

Dmitry Antipov wrote:

> Thanks, installed in r116641.

That breaks without-x builds.
Ref: http://hydra.nixos.org/build/9327212

font.c: In function 'Fframe_font_cache':
font.c:4853:3: warning: implicit declaration of function
'FRAME_DISPLAY_INFO' [-Wimplicit-function-declaration]
   return FRAME_DISPLAY_INFO (decode_live_frame (frame))->name_list_element;
   ^
font.c:4853:56: error: invalid type argument of '->' (have 'int')
   return FRAME_DISPLAY_INFO (decode_live_frame (frame))->name_list_element;
                                                        ^
make[2]: *** [font.o] Error 1





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#16069: Sigsegv, libxft, emacs --daemon, emacsclient
  2014-03-03 10:53     ` Dmitry Antipov
  2014-03-03 16:50       ` Glenn Morris
@ 2018-06-07  0:03       ` Noam Postavsky
  1 sibling, 0 replies; 5+ messages in thread
From: Noam Postavsky @ 2018-06-07  0:03 UTC (permalink / raw)
  To: Dmitry Antipov; +Cc: nil, 16069@debbugs.gnu.org

close 16069 
quit

Dmitry Antipov <dmantipov@yandex.ru> writes:

> On 03/01/2014 02:36 PM, nil wrote:
>
>> Xft fonts will be leaked
>
> Yes - if GC happens at arbitrary point after X connection is gone, there
> is no way to release font-related resources.  Anyway, better than crash.
> Installed in r116642.
>
>> (while poking around in font.c I noticed the font cache wasn't being cleared due
>> to a change of structure, something along the lines of the attached seemed to fix it.)
>
> Thanks, installed in r116641.

I guess this is okay to close then...






^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-06-07  0:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1393504047.11841.YahooMailNeo@web125304.mail.ne1.yahoo.com>
2014-02-28  6:39 ` bug#16069: emacs bug #16069 - cause & reproduction Dmitry Antipov
2014-03-01 10:36   ` nil
2014-03-03 10:53     ` Dmitry Antipov
2014-03-03 16:50       ` Glenn Morris
2018-06-07  0:03       ` bug#16069: Sigsegv, libxft, emacs --daemon, emacsclient Noam Postavsky

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.