Return-Path: Delivered-To: apmail-httpd-dev-archive@www.apache.org Received: (qmail 56369 invoked from network); 18 May 2010 07:18:55 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 18 May 2010 07:18:55 -0000 Received: (qmail 24030 invoked by uid 500); 18 May 2010 07:18:54 -0000 Delivered-To: apmail-httpd-dev-archive@httpd.apache.org Received: (qmail 23551 invoked by uid 500); 18 May 2010 07:18:51 -0000 Mailing-List: contact dev-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list dev@httpd.apache.org Received: (qmail 23537 invoked by uid 99); 18 May 2010 07:18:50 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 May 2010 07:18:50 +0000 X-ASF-Spam-Status: No, hits=-2.3 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [188.40.99.202] (HELO eru.sfritsch.de) (188.40.99.202) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 May 2010 07:18:43 +0000 Received: from stf (helo=localhost) by eru.sfritsch.de with local-esmtp (Exim 4.69) (envelope-from ) id 1OEH4J-000807-2Y; Tue, 18 May 2010 09:18:23 +0200 Date: Tue, 18 May 2010 09:18:23 +0200 (CEST) From: Stefan Fritsch To: dev@httpd.apache.org cc: dev@apr.apache.org Subject: Re: File descriptor leak with mpm-event / apr file bucket cleanup In-Reply-To: <4BF22B2E.5000304@apache.org> Message-ID: References: <201005172311.39558.sf@sfritsch.de> <4BF22B2E.5000304@apache.org> User-Agent: Alpine 1.10 (DEB 962 2008-03-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Checked: Checked by ClamAV on apache.org On Tue, 18 May 2010, Ruediger Pluem wrote: >> --- buckets/apr_buckets_file.c.dist +0200 >> +++ buckets/apr_buckets_file.c >> @@ -34,8 +34,7 @@ >> apr_bucket_file *f = data; >> >> if (apr_bucket_shared_destroy(f)) { >> - /* no need to close the file here; it will get >> - * done automatically when the pool gets cleaned up */ >> + apr_file_close(f->fd); >> apr_bucket_free(f); >> } >> } >> >> > > I guess this would be wrong. Think of the following scenario. > > 1. A brigade with a file bucket. > 2. The file bucket is split into two file buckets during processing in the > filter chain. > 3. The first bucket is processed and destroyed. This would leave the second > file bucket with an closed file descriptor. > > So if you want to close this fd you IMHO would need to do some refcounting > and only close it if no other filebucket still references it. The filebuckets already do refcounting. apr_bucket_shared_destroy(f) in the patch above is only true if the refcount has reached zero.