changeset 83522:a5d712e6585a

Fix crashes in `delete-terminal' caused by recursive calls or X displays with live frames. * src/termhooks.h (terminal) <deleted>: New member. * src/term.c (delete_tty): Use it. (deleting_tty): Remove old variable. * src/terminal.c (delete_terminal): Use terminal->deleted. * src/xterm.c (x_delete_terminal): Use terminal->deleted. Delete all frames on the display explicitly. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-562
author Karoly Lorentey <lorentey@elte.hu>
date Sat, 20 May 2006 12:20:41 +0000
parents 40a5d8a15056
children 6ce7108f7eef
files src/term.c src/termhooks.h src/terminal.c src/xterm.c
diffstat 4 files changed, 35 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/term.c	Sat May 20 12:00:16 2006 +0000
+++ b/src/term.c	Sat May 20 12:20:41 2006 +0000
@@ -2970,9 +2970,6 @@
 
 
 
-static int deleting_tty = 0;
-
-
 /* Delete the given tty terminal, closing all frames on it. */
 
 static void
@@ -2983,9 +2980,9 @@
   char *tty_name;
   int last_terminal;
   
-  if (deleting_tty)
-    /* We get a recursive call when we delete the last frame on this
-       terminal. */
+  /* Protect against recursive calls.  Fdelete_frame calls us back
+     when we delete our last frame.  */
+  if (terminal->deleted)
     return;
 
   if (terminal->type != output_termcap)
@@ -3022,7 +3019,8 @@
       tty->next = 0;
     }
 
-  deleting_tty = 1;
+  /* We must not throw any errors below this line.  */
+  terminal->deleted = 1;
 
   FOR_EACH_FRAME (tail, frame)
     {
--- a/src/termhooks.h	Sat May 20 12:00:16 2006 +0000
+++ b/src/termhooks.h	Sat May 20 12:20:41 2006 +0000
@@ -299,7 +299,11 @@
 
   /* The number of frames that are on this terminal. */
   int reference_count;
-  
+
+  /* Nonzero while deleting this terminal.  Used to protect against
+     recursive calls to delete_terminal_hook.  */
+  int deleted;
+
   /* The type of the terminal device. */
   enum output_method type;
 
--- a/src/terminal.c	Sat May 20 12:00:16 2006 +0000
+++ b/src/terminal.c	Sat May 20 12:20:41 2006 +0000
@@ -277,7 +277,13 @@
 {
   struct terminal **tp;
   Lisp_Object tail, frame;
-  
+
+  /* Protect against recursive calls.  Fdelete_frame calls us back
+     when we delete our last frame.  */
+  if (terminal->deleted)
+    return;
+  terminal->deleted = 1;
+
   /* Check for and close live frames that are still on this
      terminal. */
   FOR_EACH_FRAME (tail, frame)
--- a/src/xterm.c	Sat May 20 12:00:16 2006 +0000
+++ b/src/xterm.c	Sat May 20 12:20:41 2006 +0000
@@ -10837,6 +10837,24 @@
 {
   struct x_display_info *dpyinfo = terminal->display_info.x;
   int i;
+  Lisp_Object tail, frame;
+
+  /* Protect against recursive calls.  Fdelete_frame calls us back
+     when we delete our last frame.  */
+  if (terminal->deleted)
+    return;
+  terminal->deleted = 1;
+
+  /* Check for and close live frames that are still on this
+     terminal. */
+  FOR_EACH_FRAME (tail, frame)
+    {
+      struct frame *f = XFRAME (frame);
+      if (FRAME_LIVE_P (f) && f->terminal == terminal)
+        {
+          Fdelete_frame (frame, Qt);
+        }
+    }
 
   BLOCK_INPUT;
   /* Free the fonts in the font table.  */