emacs-diffs
[Top][All Lists]
Advanced

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

master bd034b342c: Fix accessing dpyinfo after it is deallocated


From: Po Lu
Subject: master bd034b342c: Fix accessing dpyinfo after it is deallocated
Date: Mon, 4 Jul 2022 00:56:52 -0400 (EDT)

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

    Fix accessing dpyinfo after it is deallocated
    
    * src/xterm.c (x_connection_closed): Print disconnect error for
    the last terminal before freeing it.
---
 src/xterm.c | 60 ++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 32 insertions(+), 28 deletions(-)

diff --git a/src/xterm.c b/src/xterm.c
index c5acb45083..6a357b473d 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -23501,43 +23501,47 @@ For details, see etc/PROBLEMS.\n",
         /* We have just closed all frames on this display. */
         emacs_abort ();
 
-      XSETTERMINAL (tmp, dpyinfo->terminal);
-      Fdelete_terminal (tmp, Qnoelisp);
-    }
-
-  unblock_input ();
+      /* This was the last terminal remaining, so print the error
+        message and associated error handlers and kill Emacs.  */
+      if (dpyinfo->terminal == terminal_list
+         && !terminal_list->next_terminal)
+       {
+         fprintf (stderr, "%s\n", error_msg);
 
-  if (terminal_list == 0)
-    {
-      fprintf (stderr, "%s\n", error_msg);
+         if (!ioerror && dpyinfo)
+           {
+             /* Dump the list of error handlers for debugging
+                purposes.  */
 
-      if (!ioerror)
-       {
-         /* Dump the list of error handlers for debugging
-            purposes.  */
+             fprintf (stderr, "X error handlers currently installed:\n");
 
-         fprintf (stderr, "X error handlers currently installed:\n");
+             for (failable = dpyinfo->failable_requests;
+                  failable < dpyinfo->next_failable_request;
+                  ++failable)
+               {
+                 if (failable->end)
+                   fprintf (stderr, "Ignoring errors between %lu to %lu\n",
+                            failable->start, failable->end);
+                 else
+                   fprintf (stderr, "Ignoring errors from %lu onwards\n",
+                            failable->start);
+               }
 
-         for (failable = dpyinfo->failable_requests;
-              failable < dpyinfo->next_failable_request;
-              ++failable)
-           {
-             if (failable->end)
-               fprintf (stderr, "Ignoring errors between %lu to %lu\n",
-                        failable->start, failable->end);
-             else
-               fprintf (stderr, "Ignoring errors from %lu onwards\n",
-                        failable->start);
+             for (stack = x_error_message; stack; stack = stack->prev)
+               fprintf (stderr, "Trapping errors from %lu\n",
+                        stack->first_request);
            }
-
-         for (stack = x_error_message; stack; stack = stack->prev)
-           fprintf (stderr, "Trapping errors from %lu\n",
-                    stack->first_request);
        }
 
-      Fkill_emacs (make_fixnum (70), Qnil);
+      XSETTERMINAL (tmp, dpyinfo->terminal);
+      Fdelete_terminal (tmp, Qnoelisp);
     }
 
+  unblock_input ();
+
+  if (terminal_list == 0)
+    Fkill_emacs (make_fixnum (70), Qnil);
+
   totally_unblock_input ();
 
   unbind_to (idx, Qnil);



reply via email to

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