unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* `with-output-to-string' leaks buffers
@ 2008-09-19 22:26 Romain Francoise
  2008-09-22 23:14 ` Glenn Morris
  2008-09-23  0:27 ` Stefan Monnier
  0 siblings, 2 replies; 5+ messages in thread
From: Romain Francoise @ 2008-09-19 22:26 UTC (permalink / raw)
  To: emacs-devel

Shouldn't `with-output-to-string' reap the temporary buffer it
creates even if the code it wraps exits nonlocally?

(git.el installs a function in `after-save-hook' which uses this
macro around code that signals an error, and as a result I had a
little more than 250 *string-output* buffers slowing things down
after a few days of uptime...)

2008-09-19  Romain Francoise  <romain@orebokech.com>

	* subr.el (with-output-to-string): Make sure that the temporary
	buffer gets killed.

Index: lisp/subr.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/subr.el,v
retrieving revision 1.606
diff -u -r1.606 subr.el
--- lisp/subr.el	7 Sep 2008 09:15:43 -0000	1.606
+++ lisp/subr.el	19 Sep 2008 21:56:40 -0000
@@ -2586,12 +2586,13 @@
   (declare (indent 0) (debug t))
   `(let ((standard-output
 	  (get-buffer-create (generate-new-buffer-name " *string-output*"))))
-     (let ((standard-output standard-output))
-       ,@body)
-     (with-current-buffer standard-output
-       (prog1
-	   (buffer-string)
-	 (kill-buffer nil)))))
+     (unwind-protect
+	 (progn
+	   (let ((standard-output standard-output))
+	     ,@body)
+	   (with-current-buffer standard-output
+	     (buffer-string)))
+       (kill-buffer standard-output))))
 
 (defmacro with-local-quit (&rest body)
   "Execute BODY, allowing quits to terminate BODY but not escape further.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: `with-output-to-string' leaks buffers
  2008-09-19 22:26 `with-output-to-string' leaks buffers Romain Francoise
@ 2008-09-22 23:14 ` Glenn Morris
  2008-09-23  0:27 ` Stefan Monnier
  1 sibling, 0 replies; 5+ messages in thread
From: Glenn Morris @ 2008-09-22 23:14 UTC (permalink / raw)
  To: emacs-devel

Romain Francoise wrote:

> Shouldn't `with-output-to-string' reap the temporary buffer it
> creates even if the code it wraps exits nonlocally?

FWIW, I would say yes.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: `with-output-to-string' leaks buffers
  2008-09-19 22:26 `with-output-to-string' leaks buffers Romain Francoise
  2008-09-22 23:14 ` Glenn Morris
@ 2008-09-23  0:27 ` Stefan Monnier
  2008-09-23 17:29   ` Romain Francoise
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2008-09-23  0:27 UTC (permalink / raw)
  To: emacs-devel

> Shouldn't `with-output-to-string' reap the temporary buffer it
> creates even if the code it wraps exits nonlocally?

I'd think so, yes.  Could you check the users to see if you find any
suspicious use-case?


        Stefan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: `with-output-to-string' leaks buffers
  2008-09-23  0:27 ` Stefan Monnier
@ 2008-09-23 17:29   ` Romain Francoise
  2008-09-23 18:00     ` Chong Yidong
  0 siblings, 1 reply; 5+ messages in thread
From: Romain Francoise @ 2008-09-23 17:29 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> I'd think so, yes.  Could you check the users to see if you find
> any suspicious use-case?

All the users in Emacs use it as intended and do not hold on the
buffer, so I installed my changes.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: `with-output-to-string' leaks buffers
  2008-09-23 17:29   ` Romain Francoise
@ 2008-09-23 18:00     ` Chong Yidong
  0 siblings, 0 replies; 5+ messages in thread
From: Chong Yidong @ 2008-09-23 18:00 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Romain Francoise <romain@orebokech.com> writes:

> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
>> I'd think so, yes.  Could you check the users to see if you find
>> any suspicious use-case?
>
> All the users in Emacs use it as intended and do not hold on the
> buffer, so I installed my changes.

Thanks.




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-09-23 18:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-19 22:26 `with-output-to-string' leaks buffers Romain Francoise
2008-09-22 23:14 ` Glenn Morris
2008-09-23  0:27 ` Stefan Monnier
2008-09-23 17:29   ` Romain Francoise
2008-09-23 18:00     ` Chong Yidong

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).