From 49da74e69827880a3091fd68c55b7bb3a6326dfa Mon Sep 17 00:00:00 2001
From: "Kim F. Storm" <storm@cua.dk>
Date: Fri, 13 Apr 2007 12:52:00 +0000
Subject: [PATCH] (Fkill_buffer): gcpro BUF during kill_buffer_processes and
 check that buffer is still alive upon return.

---
 src/buffer.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/buffer.c b/src/buffer.c
index 3ad92331e01..ba23cc6ae33 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1458,7 +1458,16 @@ with SIGHUP.  */)
   unlock_buffer (b);
 #endif /* CLASH_DETECTION */
 
+  GCPRO1 (buf);
   kill_buffer_processes (buf);
+  UNGCPRO;
+
+  /* Killing buffer processes may run sentinels which may
+     have called kill-buffer.  */
+
+  if (NILP (b->name))
+    return Qnil;
+
   clear_charpos_cache (b);
 
   tem = Vinhibit_quit;
-- 
2.39.5