# HG changeset patch
# User Richard M. Stallman <rms@gnu.org>
# Date 1040492798 0
# Node ID 0d51b82bd792b90911b620ebb73f704629932462
# Parent  bf2ca45780bea4cc9f967e4ee206ca39c6bca2d6
(file_name_completion): Close directory on error

diff -r bf2ca45780be -r 0d51b82bd792 src/dired.c
--- a/src/dired.c	Sat Dec 21 17:06:54 2002 +0000
+++ b/src/dired.c	Sat Dec 21 17:46:38 2002 +0000
@@ -523,6 +523,10 @@
       if (!d)
 	report_file_error ("Opening directory", Fcons (dirname, Qnil));
 
+      record_unwind_protect (directory_files_internal_unwind,
+                             Fcons (make_number (((unsigned long) d) >> 16),
+                                    make_number (((unsigned long) d) & 0xffff)));
+
       /* Loop reading blocks */
       /* (att3b compiler bug requires do a null comparison this way) */
       while (1)
@@ -716,10 +720,11 @@
 	    }
 	}
       closedir (d);
+      /* Discard the unwind protect.  */
+      specpdl_ptr = specpdl + count;
     }
 
   UNGCPRO;
-  bestmatch = unbind_to (count, bestmatch);
 
   if (all_flag || NILP (bestmatch))
     {
@@ -738,6 +743,8 @@
 
  quit:
   if (d) closedir (d);
+  /* Discard the unwind protect.  */
+  specpdl_ptr = specpdl + count;
   Vquit_flag = Qnil;
   return Fsignal (Qquit, Qnil);
 }