Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[bug] fd leak when zchdir to TOOLONG paths
- X-seq: zsh-workers 20591
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxxxxx>
- Subject: [bug] fd leak when zchdir to TOOLONG paths
- Date: Mon, 29 Nov 2004 11:57:00 +0000
- Mail-followup-to: Zsh hackers list <zsh-workers@xxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
Reproduce it with:
cd /tmp/
repeat 500 { mkdir blahblahblah; cd blahblahblah }
Then lsof -p $$ >&2
(you may have troubles as the fds may interact with internal fd
handling stdout (1 being closed!)).
A simple fix would be:
--- ../cvs/zsh/Src/compat.c	2002-08-05 13:35:59.000000000 +0100
+++ ./Src/compat.c	2004-11-29 11:54:26.000000000 +0000
@@ -387,10 +387,20 @@
     int currdir = -2;
 
     for (;;) {
-	if (!*dir)
-	    return 0;
-	if (!chdir(dir))
+	if (*dir == '\0') {
+#ifdef HAVE_FCHDIR
+	    if (currdir >= 0)
+		close(currdir);
+#endif
 	    return 0;
+	}
+	if (chdir(dir) == 0) {
+#ifdef HAVE_FCHDIR
+	    if (currdir >= 0)
+		close(currdir);
+#endif
+	    return 0; /* chdir successful */
+	}
 	if ((errno != ENAMETOOLONG && errno != ENOMEM) ||
 	    strlen(dir) < PATH_MAX)
 	    break;
-- 
Stéphane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author