summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Src/compat.c10
2 files changed, 10 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 4775b505d..3a9981dda 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2004-11-29  Peter Stephenson  <pws@csr.com>
 
+	* 20591: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>:
+	use of fchdir to change directory leaked filed descriptors.
+
 	* 20592: Src/math.c: $((##)) caused mayhem by passing null
 	string to getkeystring().  Report error instead.
 
diff --git a/Src/compat.c b/Src/compat.c
index 2999e63e4..ba077d3a0 100644
--- a/Src/compat.c
+++ b/Src/compat.c
@@ -387,10 +387,14 @@ zchdir(char *dir)
     int currdir = -2;
 
     for (;;) {
-	if (!*dir)
-	    return 0;
-	if (!chdir(dir))
+	if (!*dir || !chdir(dir))
+	{
+#ifdef HAVE_FCHDIR
+           if (currdir >= 0)
+               close(currdir);
+#endif
 	    return 0;
+	}
 	if ((errno != ENAMETOOLONG && errno != ENOMEM) ||
 	    strlen(dir) < PATH_MAX)
 	    break;