Subject: Re: bug#74902: 31.0.50; Segfault when deleting frames

From: Steven Allen <[email-masked]>
Date: Tue, 31 Dec 2024 08:31:04 -0800

Eli Zaretskii <[email-masked]> writes:
> Thanks.  I guess we also need a FRAME_LIVE_P test in
> gui_consider_frame_title?

I've attached a patch for that but note that it doesn't actually help in
this situation because the frame isn't deleted until:

https://git.savannah.gnu.org/cgit/emacs.git/tree/src/frame.c?h=2f1052d9b0de551dc3a463ed54e21c63517497ab#n2536

Whereas the crash happens here, 36 lines above:

https://git.savannah.gnu.org/cgit/emacs.git/tree/src/frame.c?h=2f1052d9b0de551dc3a463ed54e21c63517497ab#n2500

>From 4f4907bf1657b5128dc045161272c360029c6f6a Mon Sep 17 00:00:00 2001
From: Steven Allen <[email-masked]>
Date: Tue, 31 Dec 2024 07:48:47 -0800
Subject: [PATCH] Avoid operating on dead frames when updating titles

* src/xdisp.c (gui_consider_frame_title): Skip over dead/dying frames
when updating frame title.  (Bug#74902)
---
 src/xdisp.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/xdisp.c b/src/xdisp.c
index ceb727d1135..d2ba8b10c80 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -13858,9 +13858,10 @@ gui_consider_frame_title (Lisp_Object frame)
   struct frame *f = XFRAME (frame);
   Lisp_Object format_data;
 
-  if ((FRAME_WINDOW_P (f)
-       || FRAME_MINIBUF_ONLY_P (f)
-       || f->explicit_name)
+  if (FRAME_LIVE_P (f)
+      && (FRAME_WINDOW_P (f)
+	  || FRAME_MINIBUF_ONLY_P (f)
+	  || f->explicit_name)
       && !FRAME_TOOLTIP_P (f))
     {
       /* Do we have more than one visible frame on this X display?  */
@@ -13875,6 +13876,9 @@ gui_consider_frame_title (Lisp_Object frame)
 	{
 	  struct frame *tf = XFRAME (other_frame);
 
+	  if (!FRAME_LIVE_P (tf))
+	    continue;
+
 	  if (tf != f
 	      && FRAME_KBOARD (tf) == FRAME_KBOARD (f)
 	      && !FRAME_MINIBUF_ONLY_P (tf)
-- 
2.47.1