zsh-workers
 help / color / mirror / code / Atom feed
* [bug] fd leak when zchdir to TOOLONG paths
@ 2004-11-29 11:57 Stephane Chazelas
  2004-11-29 12:10 ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Stephane Chazelas @ 2004-11-29 11:57 UTC (permalink / raw)
  To: Zsh hackers list

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-11-29 16:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-29 11:57 [bug] fd leak when zchdir to TOOLONG paths Stephane Chazelas
2004-11-29 12:10 ` Peter Stephenson
2004-11-29 15:34   ` OT: Coding (was Re: [bug] fd leak) Bart Schaefer
2004-11-29 16:42   ` zsh coding standards Wayne Davison
2004-11-29 16:52     ` Peter Stephenson
2004-11-29 16:57     ` Alexandre Duret-Lutz

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).