summary refs log tree commit diff
path: root/Src/compat.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2004-11-29 12:09:13 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2004-11-29 12:09:13 +0000
commitd2c67e5e19953c2bee353635c3e8aec7c38f8d57 (patch)
treeb67937542b8d5290bb1fa657236172651ee9e991 /Src/compat.c
parentcebe5f1d10418b6fc7dec0eab5bfe5d62bd0bb74 (diff)
downloadzsh-d2c67e5e19953c2bee353635c3e8aec7c38f8d57.tar.gz
zsh-d2c67e5e19953c2bee353635c3e8aec7c38f8d57.tar.xz
zsh-d2c67e5e19953c2bee353635c3e8aec7c38f8d57.zip
20591: Stephane Chazelas: use of fchdir in zchdir leaked fd's
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;