Subject: bug#39344: 28.0.50; Gnus: Selecting deleted buffer

From: Stephen Berman <[email-masked]>
Date: Wed, 29 Jan 2020 14:07:16 +0100

On Wed, 29 Jan 2020 12:48:42 +0100 Michael Heerdegen <[email-masked]> wrote:

> Hello,
>
> since today (master built) when exiting Gnus I get this error:
>
> Debugger entered--Lisp error: (error "Selecting deleted buffer")
>   set-buffer(#<killed buffer>)
[...]
> Could this be due to
>
> | Make sure that all gnus buffers are killed on exit
> | 5ee3c37634f7f8651b2da1f4b611334a2b146928
> | Author:     Sam Steingold <[email-masked]>
> | AuthorDate: Fri Jan 10 13:34:59 2020 -0500
>
> ?
>
> AFAICT `my-gnus-clear-system-around-ad' is unrelated, it looks like
>
> (defun my-gnus-clear-system-around-ad (f &rest args)
>               (let ((kill-buffer-query-functions kill-buffer-query-functions))
>                 (remove-hook 'kill-buffer-query-functions 'process-kill-buffer-query-function)
>                 (apply f args)))
>
> The problem rather seems to be that the return value of (gnus-buffers)
> contains killed buffers.

I see this too.  The patch below appears to fix it for me, but I don't
know if it's just a workaround.

Steve Berman

diff --git a/lisp/gnus/gnus-start.el b/lisp/gnus/gnus-start.el
index 1fd2575ea1..5dba7cced7 100644
--- a/lisp/gnus/gnus-start.el
+++ b/lisp/gnus/gnus-start.el
@@ -722,11 +722,12 @@ gnus-clear-system
   ;; Kill Gnus buffers.
   (do-auto-save t)
   (dolist (buffer (gnus-buffers))
-    (with-current-buffer buffer
-      (set-buffer-modified-p nil)
-      (when (local-variable-p 'kill-buffer-hook)
-        (setq kill-buffer-hook nil)))
-    (gnus-kill-buffer buffer))
+    (when (buffer-live-p buffer)
+      (with-current-buffer buffer
+	(set-buffer-modified-p nil)
+	(when (local-variable-p 'kill-buffer-hook)
+	  (setq kill-buffer-hook nil)))
+      (gnus-kill-buffer buffer)))
   ;; Remove Gnus frames.
   (gnus-kill-gnus-frames))