changeset 99554:ae79259858c8

(Finsert_file_contents): Decrement specpdl_ptr to avoid double file close.
author Chong Yidong <cyd@stupidchicken.com>
date Fri, 14 Nov 2008 21:11:15 +0000
parents 54af6e9e3b4e
children c7babe27159c
files src/fileio.c
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/fileio.c	Fri Nov 14 21:10:43 2008 +0000
+++ b/src/fileio.c	Fri Nov 14 21:11:15 2008 +0000
@@ -3144,6 +3144,7 @@
   int read_quit = 0;
   Lisp_Object old_Vdeactivate_mark = Vdeactivate_mark;
   int we_locked_file = 0;
+  int deferred_remove_unwind_protect = 0;
 
   if (current_buffer->base_buffer && ! NILP (visit))
     error ("Cannot do file visiting in an indirect buffer");
@@ -3656,6 +3657,11 @@
       UNGCPRO;
       emacs_close (fd);
 
+      /* We should remove the unwind_protect calling
+	 close_file_unwind, but other stuff has been added the stack,
+	 so defer the removal till we reach the `handled' label.  */
+      deferred_remove_unwind_protect = 1;
+
       /* At this point, HOW_MUCH should equal TOTAL, or should be <= 0
 	 if we couldn't read the file.  */
 
@@ -4037,6 +4043,11 @@
 
  handled:
 
+  if (deferred_remove_unwind_protect)
+    /* If requested above, discard the unwind protect for closing the
+       file.  */
+    specpdl_ptr--;
+
   if (!NILP (visit))
     {
       if (!EQ (current_buffer->undo_list, Qt) && !nochange)