justbur / emacs-which-key

Emacs package that displays available keybindings in popup
GNU General Public License v3.0
1.74k stars 87 forks source link

Pressing "# C-g" in *Ediff Control Panel*" causes Emacs to freeze and leak memory #317

Closed shitikanth closed 1 year ago

shitikanth commented 3 years ago

Steps to reproduce:

  1. Start emacs with emacs -Q -L $which-key-srcdir -l bug.el (just loads which-key and starts ediff on two empty buffers).
  2. Press # C-g. (Sometimes it takes a couple of tries before it crashes,)
;;; bug.el
(require 'which-key)
(which-key-mode)

(let ((buf-a (generate-new-buffer "temp"))
      (buf-b (generate-new-buffer "temp")))
  (ediff-buffers buf-a buf-b))

Lisp backtrace from gdb:

(gdb) xbacktrace 
"format" (0xffffade0)
"seq-subseq" (0xffffb168)
"cl-subseq" (0xffffb3c0)
"cons" (0xffffb4f0)
"setq" (0xffffb5c0)
"while" (0xffffb690)
"let" (0xffffb7a0)
"which-key--partition-list" (0xffffb890)
"mapcar" (0xffffb9c0)
"let" (0xffffbb20)
"which-key--list-to-pages" (0xffffbc10)
"let" (0xffffbdd0)
"which-key--create-pages-1" (0xffffbec0)
"setq" (0xffffc030)
"let*" (0xffffc120)
"which-key--create-pages" (0xffffc210)
"setq" (0xffffc370)
"cond" (0xffffc430)
"let" (0xffffc550)
"which-key--create-buffer-and-show" (0xffffc640)
"progn" (0xffffc770)
"if" (0xffffc810)
"cond" (0xffffc8d0)
"let" (0xffffc9f0)
"which-key--update" (0xffffcc30)
"apply" (0xffffcc28)
"timer-event-handler" (0xffffcfa8)
shitikanth commented 3 years ago

Found the issue: in the default gui setup, ediff control panel lives in a tiny frame of height of 1 line where (which-key--popup-max-dimensions) returns (0 . 12) and which-key then tries to partition the results into groups of zero.

Possible fixes:

  1. We could show the completion in the other frame. This is where the minibuffer lives and this will be consistent with how M-x, M-: etc behave in the ediff control panel.
  2. We could just not show anything at all when number of rows is 0.
shitikanth commented 1 year ago

@justbur any feedback on this?

justbur commented 1 year ago

Sorry for the delay.

Thank you for the report and the diagnosis.