about summary refs log tree commit diff
path: root/Src/compat.c
diff options
context:
space:
mode:
Diffstat (limited to 'Src/compat.c')
-rw-r--r--Src/compat.c10
1 files changed, 7 insertions, 3 deletions
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;