From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25398 invoked from network); 29 Nov 2004 11:57:45 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 29 Nov 2004 11:57:45 -0000 Received: (qmail 82685 invoked from network); 29 Nov 2004 11:57:39 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 29 Nov 2004 11:57:39 -0000 Received: (qmail 6977 invoked by alias); 29 Nov 2004 11:57:33 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 20591 Received: (qmail 6905 invoked from network); 29 Nov 2004 11:57:31 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 29 Nov 2004 11:57:31 -0000 Received: (qmail 79835 invoked from network); 29 Nov 2004 11:56:54 -0000 Received: from smtp-out5.blueyonder.co.uk (195.188.213.8) by a.mx.sunsite.dk with SMTP; 29 Nov 2004 11:56:52 -0000 Received: from sc ([82.41.236.21]) by smtp-out5.blueyonder.co.uk with Microsoft SMTPSVC(5.0.2195.6713); Mon, 29 Nov 2004 11:57:22 +0000 Date: Mon, 29 Nov 2004 11:57:00 +0000 From: Stephane Chazelas To: Zsh hackers list Subject: [bug] fd leak when zchdir to TOOLONG paths Message-ID: <20041129115700.GA4569@sc> Mail-Followup-To: Zsh hackers list Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.5.6i X-OriginalArrivalTime: 29 Nov 2004 11:57:22.0081 (UTC) FILETIME=[95951910:01C4D60A] X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=-0.0 required=6.0 tests=BAYES_44 autolearn=no version=2.63 X-Spam-Hits: -0.0 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