Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm 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 X-Authentication-Warning: slinky.cs.nyu.edu: pechtcha owned process doing -bs Date: Tue, 10 Dec 2002 11:55:09 -0500 (EST) From: Igor Pechtchanski Reply-To: cygwin AT cygwin DOT com To: cygwin AT cygwin DOT com Subject: Re: cygwin 1.3.17-1 gethostbyname() leak In-Reply-To: <20021210173645.D26891@cygbert.vinschen.de> Message-ID: Importance: Normal MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Tue, 10 Dec 2002, Corinna Vinschen wrote: > On Tue, Dec 10, 2002 at 10:36:04AM -0500, Igor Pechtchanski wrote: > > On Tue, 10 Dec 2002, Noel Gordon wrote: > > > > > Anyone else confirm that the following program compiled under > > > gcc 3.2, cygwin 1.3.17-1, on Win2k leaks memory? > > Confirmed. I found the missing free(). > > > >From http://www.opengroup.org/onlinepubs/007904975/functions/gethostbyaddr.html : > > > > The gethostbyaddr() and gethostbyname() functions *may* return > > pointers to static data, which may be overwritten by subsequent > > calls to any of these functions. > > > > The "may" above (emphasis is mine) means that the implementation is free > > to malloc a data structure and require the user to free it. Since you > > don't free the returned data structure in your program, it's quite > > possible that there's a leak. Also, Cygwin uses the gethostbyname from > > wsock32.dll, which may have different implementations on different > > systems. Thus, your best bet is to look up gethostbyname on MSDN for > > implementation details. > > Ignore MSDN. It's using an internal per-thread buffer which collides with > the fork/exec mechanism of Cygwin so Cygwin duplicates the buffer to > another Cygwin-thread specific allocated buffer. The deallocation of > the buffer is Cygwin internal so hands off please. > > Thanks for the report, I've checked in a patch, > Corinna Umm, note to self: always browse *all* of the relevant code before expressing opinions on the cygwin list! Apologies to all for the misinformation. I've found the gethostbyname entry in autoload.cc and did not look further. Had I paid more attention, I would have noticed the cygwin_gethostbyname() in net.cc, which is the actual implementation and does what Corinna said. Igor -- http://cs.nyu.edu/~pechtcha/ |\ _,,,---,,_ pechtcha AT cs DOT nyu DOT edu ZZZzz /,`.-'`' -. ;-;;,_ igor AT watson DOT ibm DOT com |,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow! "Water molecules expand as they grow warmer" (C) Popular Science, Oct'02, p.51 -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/