unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 71929@debbugs.gnu.org, Sean Whitton <spwhitton@spwhitton.name>
Subject: bug#71929: 30.0.60; crash in mark_image_cache
Date: Sun, 07 Jul 2024 15:41:53 +0800	[thread overview]
Message-ID: <875xth3aym.fsf@yahoo.com> (raw)
In-Reply-To: <86a5it3cj2.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 07 Jul 2024 10:08:01 +0300")

Eli Zaretskii <eliz@gnu.org> writes:

> This is the initial frame of the daemon.  It is not a GUI frame, and
> so it should not have a valid image cache.  I guess some change is
> needed in verify_image_cache_refcount?

Not quite: init_frame_faces is apparently called before the frame is
entered into Vframe_list, so, likewise, the face cache's reference count
should be verified before it is incremented.

Sean, please retry with this patch substituted for the previous:

diff --git a/src/frame.c b/src/frame.c
index 7f4bf274ad9..9793b9f5cbe 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -4831,14 +4831,20 @@ gui_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 	  /* Clean F's image cache of images whose values are derived
 	     from the font width.  */
 	  clear_image_cache (f, Qauto);
+	  verify_image_cache_refcount (FRAME_IMAGE_CACHE (f));
 	}
       else
 	{
+	  struct image_cache *old_cache = FRAME_IMAGE_CACHE (f);
+
 	  /* Release the current image cache, and reuse or allocate a
 	     new image cache with IWIDTH.  */
 	  FRAME_IMAGE_CACHE (f)->refcount--;
+	  FRAME_IMAGE_CACHE (f) = NULL;
+	  verify_image_cache_refcount (old_cache);
 	  FRAME_IMAGE_CACHE (f) = share_image_cache (f);
 	  FRAME_IMAGE_CACHE (f)->refcount++;
+	  verify_image_cache_refcount (FRAME_IMAGE_CACHE (f));
 	}
     }
 
diff --git a/src/frame.h b/src/frame.h
index 1d920d1a6bc..8a636c56643 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -1682,6 +1682,31 @@ IMAGE_OPT_FROM_ID (struct frame *f, int id)
   eassume (0 <= used);
   return 0 <= id && id < used ? FRAME_IMAGE_CACHE (f)->images[id] : NULL;
 }
+
+/* Abort if C is non-NULL and C's `refcount' field disagrees with the
+   number of frames holding references to the same.  */
+
+INLINE void
+verify_image_cache_refcount (struct image_cache *c)
+{
+  int expected;
+  Lisp_Object tail, frame;
+
+  if (c)
+    {
+      expected = 0;
+
+      FOR_EACH_FRAME (tail, frame)
+	{
+	  if (FRAME_IMAGE_CACHE (XFRAME (frame)) == c)
+	    expected++;
+	}
+
+      if (expected != c->refcount)
+	emacs_abort ();
+    }
+}
+
 #endif
 \f
 /***********************************************************************
diff --git a/src/image.c b/src/image.c
index 2945447b962..9387c78408b 100644
--- a/src/image.c
+++ b/src/image.c
@@ -3625,6 +3625,7 @@ cache_image (struct frame *f, struct image *img)
     {
       c = FRAME_IMAGE_CACHE (f) = share_image_cache (f);
       c->refcount++;
+      verify_image_cache_refcount (c);
     }
 
   /* Find a free slot in c->images.  */
diff --git a/src/xfaces.c b/src/xfaces.c
index 188dd4778bc..ed4d404fbf3 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -678,7 +678,10 @@ init_frame_faces (struct frame *f)
   /* Make or share an image cache.  */
   if (FRAME_WINDOW_P (f))
     {
-      FRAME_IMAGE_CACHE (f) = share_image_cache (f);
+      struct image_cache *c = share_image_cache (f);
+
+      verify_image_cache_refcount (c);
+      FRAME_IMAGE_CACHE (f) = c;
       ++FRAME_IMAGE_CACHE (f)->refcount;
     }
 #endif /* HAVE_WINDOW_SYSTEM */
@@ -709,6 +712,7 @@ free_frame_faces (struct frame *f)
       struct image_cache *image_cache = FRAME_IMAGE_CACHE (f);
       if (image_cache)
 	{
+	  verify_image_cache_refcount (image_cache);
 	  --image_cache->refcount;
 	  if (image_cache->refcount == 0)
 	    free_image_cache (f);





  reply	other threads:[~2024-07-07  7:41 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-04  2:33 bug#71929: 30.0.60; crash in mark_image_cache Sean Whitton
2024-07-04  2:44 ` Sean Whitton
2024-07-04  5:53   ` Eli Zaretskii
2024-07-04  6:03     ` Eli Zaretskii
2024-07-04  6:17       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-04  6:42         ` Sean Whitton
2024-07-04  6:59           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-04  9:56             ` Sean Whitton
2024-07-04 12:28               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-05  7:52                 ` Sean Whitton
2024-07-04  7:40           ` Eli Zaretskii
2024-07-04  9:57             ` Sean Whitton
2024-07-04 12:48               ` Eli Zaretskii
2024-07-05  0:13       ` Sean Whitton
2024-07-05  6:27         ` Eli Zaretskii
2024-07-05  6:41           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-05  7:37             ` Eli Zaretskii
2024-07-05  9:36               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-05 11:10                 ` Eli Zaretskii
2024-07-05 11:40                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-05 12:46                     ` Sean Whitton
2024-07-06  2:41                     ` Sean Whitton
2024-07-06  6:08                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-07  2:40                         ` Sean Whitton
2024-07-07  2:43                         ` Sean Whitton
2024-07-07  2:46                           ` Sean Whitton
2024-07-07  4:04                             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-07  4:54                               ` Sean Whitton
2024-07-07  7:08                                 ` Eli Zaretskii
2024-07-07  7:41                                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-07-07 13:16                                     ` Sean Whitton
2024-07-07 13:47                                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-07 14:45                                         ` Sean Whitton
2024-07-09  5:48                                         ` Sean Whitton
2024-07-09 11:37                                           ` Eli Zaretskii
2024-07-10  1:12                                             ` Sean Whitton
2024-07-09 12:13                                           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-09 13:44                                             ` Sean Whitton
2024-07-09 14:03                                               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-09 14:18                                                 ` Eli Zaretskii
2024-07-09 15:02                                                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-09 15:45                                                     ` Eli Zaretskii
2024-07-10  1:12                                                 ` Sean Whitton
2024-07-24 13:31                                                   ` Basil L. Contovounesios
2024-07-24 13:38                                                     ` Eli Zaretskii
2024-07-24 14:10                                                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-06  6:40                       ` Eli Zaretskii
2024-07-07  2:39                         ` Sean Whitton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875xth3aym.fsf@yahoo.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=71929@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=luangruo@yahoo.com \
    --cc=spwhitton@spwhitton.name \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).