X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,TW_OC,TW_YF,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Message-ID: <4DAC4B6A.50101@lysator.liu.se> Date: Mon, 18 Apr 2011 16:32:10 +0200 From: Peter Rosin User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: Memory leak in select References: <4DAC23E3 DOT 2020005 AT lysator DOT liu DOT se> <4DAC2D35 DOT 5070106 AT lysator DOT liu DOT se> In-Reply-To: <4DAC2D35.5070106@lysator.liu.se> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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? Cheers, Peter extern "C" int cygwin_select (int maxfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *to) { select_stuff sel; fd_set *dummy_readfds = allocfd_set (maxfds); fd_set *dummy_writefds = allocfd_set (maxfds); fd_set *dummy_exceptfds = allocfd_set (maxfds); ... sel.cleanup (); // Too early ??? copyfd_set (readfds, r, maxfds); copyfd_set (writefds, w, maxfds); copyfd_set (exceptfds, e, maxfds); return timeout ? 0 : sel.poll (readfds, writefds, exceptfds); } -- 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