From 52eb77a6ad5df5980bc8c6d7ad7ee802feb8add3 Mon Sep 17 00:00:00 2001
From: Chong Yidong <cyd@stupidchicken.com>
Date: Sun, 27 Feb 2011 17:57:22 -0500
Subject: [PATCH] Avoid recording dead buffers in buffer-list frame param
 (Bug#7898).

* src/frame.c (store_frame_param): Don't store value directly in
buffer_list and buried_buffer_list; copy the list and remove dead
buffers.
---
 src/ChangeLog |  6 ++++++
 src/frame.c   | 14 +++++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index a7c9d4c7e3c..0e5e295a622 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2011-02-27  Chong Yidong  <cyd@stupidchicken.com>
+
+	* frame.c (store_frame_param): Don't store value directly in
+	buffer_list and buried_buffer_list; copy the list and remove dead
+	buffers (Bug#7898).
+
 2011-02-27  Eli Zaretskii  <eliz@gnu.org>
 
 	* msdos.c (readlink) [DJGPP < 2.04]: New stub function.
diff --git a/src/frame.c b/src/frame.c
index 3a6900a572a..05938f3e1f0 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -2208,15 +2208,23 @@ store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
   register Lisp_Object old_alist_elt;
 
   /* The buffer-list parameters are stored in a special place and not
-     in the alist.  */
+     in the alist.  All buffers must be live.  */
   if (EQ (prop, Qbuffer_list))
     {
-      f->buffer_list = val;
+      Lisp_Object list = Qnil;
+      for (; CONSP (val); val = XCDR (val))
+	if (!NILP (Fbuffer_live_p (XCAR (val))))
+	  list = Fcons (XCAR (val), list);
+      f->buffer_list = Fnreverse (list);
       return;
     }
   if (EQ (prop, Qburied_buffer_list))
     {
-      f->buried_buffer_list = val;
+      Lisp_Object list = Qnil;
+      for (; CONSP (val); val = XCDR (val))
+	if (!NILP (Fbuffer_live_p (XCAR (val))))
+	  list = Fcons (XCAR (val), list);
+      f->buried_buffer_list = Fnreverse (list);
       return;
     }
 
-- 
2.39.5