From: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>
To: Zsh hackers list <zsh-workers@sunsite.dk>
Subject: [bug] fd leak when zchdir to TOOLONG paths
Date: Mon, 29 Nov 2004 11:57:00 +0000 [thread overview]
Message-ID: <20041129115700.GA4569@sc> (raw)
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
next reply other threads:[~2004-11-29 11:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-11-29 11:57 Stephane Chazelas [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20041129115700.GA4569@sc \
--to=stephane_chazelas@yahoo.fr \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).