From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22644 invoked by alias); 20 Apr 2011 01:11:16 -0000 Received: (qmail 22635 invoked by uid 22791); 20 Apr 2011 01:11:15 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY X-Spam-Check-By: sourceware.org Received: from nm26.bullet.mail.sp2.yahoo.com (HELO nm26.bullet.mail.sp2.yahoo.com) (98.139.91.96) by sourceware.org (qpsmtpd/0.43rc1) with SMTP; Wed, 20 Apr 2011 01:11:00 +0000 Received: from [98.139.91.68] by nm26.bullet.mail.sp2.yahoo.com with NNFMP; 20 Apr 2011 01:10:59 -0000 Received: from [98.136.185.44] by tm8.bullet.mail.sp2.yahoo.com with NNFMP; 20 Apr 2011 01:10:59 -0000 Received: from [127.0.0.1] by smtp105.mail.gq1.yahoo.com with NNFMP; 20 Apr 2011 01:10:59 -0000 Received: from cgf.cx (cgf@96.252.118.15 with login) by smtp105.mail.gq1.yahoo.com with SMTP; 19 Apr 2011 18:10:59 -0700 PDT X-Yahoo-SMTP: jenXL62swBAWhMTL3wnej93oaS0ClBQOAKs8jbEbx_o- Received: from localhost (ednor.casa.cgf.cx [192.168.187.5]) by cgf.cx (Postfix) with ESMTP id 060244A8045 for ; Tue, 19 Apr 2011 21:10:58 -0400 (EDT) Date: Wed, 20 Apr 2011 05:16:00 -0000 From: Christopher Faylor To: cygwin@cygwin.com Subject: Re: Memory leak in select Message-ID: <20110420011057.GA453@ednor.casa.cgf.cx> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: <4DAC23E3.2020005@lysator.liu.se> <4DAC2D35.5070106@lysator.liu.se> <4DAC4B6A.50101@lysator.liu.se> <20110418152441.GA12913@ednor.casa.cgf.cx> <20110418152801.GA11182@ednor.casa.cgf.cx> <4DAC8F96.3080808@lysator.liu.se> <4DADFF3A.1060006@lysator.liu.se> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4DADFF3A.1060006@lysator.liu.se> User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2011-04/txt/msg00289.txt.bz2 On Tue, Apr 19, 2011 at 11:31:38PM +0200, Peter Rosin wrote: >Den 2011-04-18 21:23 skrev Peter Rosin: >> Den 2011-04-18 17:28 skrev Christopher Faylor: >>> On Mon, Apr 18, 2011 at 11:24:41AM -0400, Christopher Faylor wrote: >>>> On Mon, Apr 18, 2011 at 04:32:10PM +0200, Peter Rosin wrote: >>>>> Den 2011-04-18 14:23 skrev Peter Rosin: >>>>>> Den 2011-04-18 13:43 skrev Peter Rosin: >>>>>>> Hi! >>>>>>> >>>>>>> Using the following STC, I'm seeing what appears to be a memory >>>>>>> leak in select(2). >>>>>>> >>>>>> ----------------8<---(selectleak.c)--------- >>>>>> #include >>>>>> #include >>>>>> >>>>>> int >>>>>> main(void) >>>>>> { >>>>>> fd_set fdset; >>>>>> >>>>>> long flags = fcntl(0, F_GETFL); >>>>>> fcntl(0, F_SETFL, flags | O_NONBLOCK); >>>>>> >>>>>> for (;;) { >>>>>> int res; >>>>>> char buf[20]; >>>>>> >>>>>> FD_ZERO(&fdset); >>>>>> FD_SET(0, &fdset); >>>>>> res = select(1, &fdset, NULL, NULL, NULL); >>>>>> if (!res) >>>>>> continue; >>>>>> if (res < 0) >>>>>> return 1; >>>>>> res = read(0, buf, sizeof(buf)); >>>>>> if (!res) >>>>>> break; >>>>>> if (res < 0) >>>>>> return 1; >>>>>> } >>>>>> >>>>>> return 0; >>>>>> } >>>>>> ----------------8<-------------------------- >>>>> >>>>> Ok, I'm taking a wild swing at this, and my guess is that the call >>>>> sel.cleanup () in cygwin_select prematurely zeros out the cleanup >>>>> member of the select_record. The call to sel.poll () then adds >>>>> "stuff" to the select_record that really should have been cleaned >>>>> up, but isn't since cleanup has already been executed and then >>>>> zapped (by select_stuff::cleanup). >>>>> >>>>> But what do I know? >>>> >>>> How does sel.poll add "stuff" that should be cleaned up? That function >>>> only looks for bits to set. >> >> I shouldn't have included the strace, and I shouldn't have guessed about >> the cause of the problem without verifying my claims. Sorry about that. >> But for the record the included strace snippet is reoccurring like that >> many many times (the address of the allocation that isn't freed is >> moving). Further evidence; the STC leaks 1 MB every 3 seconds on my >> computer, that just can't be right. > >Back with a patch this time. Fixes it for me... > >Cheers, >Peter > >2011-04-19 Peter Rosin > > * select.cc (pipe_cleanup): Don't leak a select_pipe_info when a > thread turned out not to be needed. Makes sense. I've checked this in (with a different ChangeLog). Thanks for the patch. cgf -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple