X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org Date: Thu, 20 Aug 2009 13:19:55 +0200 From: Corinna Vinschen To: cygwin AT cygwin DOT com Subject: Re: find(1) memory leak in cygheap Message-ID: <20090820111955.GP32408@calimero.vinschen.de> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <20090819140322 DOT GB8713 AT ednor DOT casa DOT cgf DOT cx> <20090820083926 DOT GJ32408 AT calimero DOT vinschen DOT de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.19 (2009-02-20) Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: 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 On Aug 20 18:23, Haojun Bao wrote: > On Thu, Aug 20, 2009 at 4:39 PM, Corinna > Vinschen wrote: > > On Aug 20 14:09, Haojun Bao wrote: > >> I have done some debugging, and the culprit should be dup(2) syscall. > >> Here's another test case, this time written in C. > >> > >> Note that the cygheap_start and cygheap_max value will be very likely > >> different on your computer, so you should use gdb to take a peek into > >> cygwin1.dll to get your value. Or else you should remove the reference > >> to these memory location. > >> > >> The test case will show cygheap is always growing, and at the end it will print > >>   1 [main] a 3560 Q:\a.exe: *** fatal error - cmalloc would have returned NULL > > > > Thanks for the testcase!  It was pretty easy to find the culprit with > > it.  Deep in dup(), the strings for the filenames of the new file > > descriptor were allocated twice.  While I was at it, I also found two > > other potential memory leaks, which would just show up much less > > frequent. > > > > This fixes your find testcase as well, and probably (hopefully?) also > > the problem reported in http://cygwin.com/ml/cygwin/2009-08/msg00620.html > > > > I applied a patch to CVS and will upload a -60 release asap. > > > > > > Thanks again, > > Corinna > > > Great. In fact, I also found this code myself might cause problem in path.h: > (we should test if path is NULL, and free it before the memcpy, and > other member pointers should also be checked and free-ed first, is it > about right?:-) Yes and no. It might look cleaner to free the pointers at this point if they are non-NULL, but in fact the operator= is called after the path_conv content has been memcpy'ed to another fhandler. So, if you free the pointers, you free the pointers of another file descriptor. SEGV's galore! Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Project Co-Leader cygwin AT cygwin DOT com Red Hat -- 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