]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/emacs-lisp/thunk.el (thunk-delay): Fix memory leak
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 4 Jun 2019 16:55:53 +0000 (12:55 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Tue, 4 Jun 2019 16:55:53 +0000 (12:55 -0400)
Get rid of references to the free variables of `body` once the thunk has
been forced (bug#30626).

lisp/emacs-lisp/thunk.el

index e1370c459117f66d9c1f7897089951630a3fa7e6..8d28570dc2a279a1a2863081afe6319dd5d0437e 100644 (file)
   "Delay the evaluation of BODY."
   (declare (debug t))
   (cl-assert lexical-binding)
-  (let ((forced (make-symbol "forced"))
-        (val (make-symbol "val")))
-    `(let (,forced ,val)
-       (lambda (&optional check)
-         (if check
-             ,forced
-           (unless ,forced
-             (setf ,val (progn ,@body))
-             (setf ,forced t))
-           ,val)))))
+  `(let (forced
+         (val (lambda () ,@body)))
+     (lambda (&optional check)
+       (if check
+           forced
+         (unless forced
+           (setf val (funcall val))
+           (setf forced t))
+         val))))
 
 (defun thunk-force (delayed)
   "Force the evaluation of DELAYED.