Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[bug] fd leak when zchdir to TOOLONG paths



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