This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: cygwin 1.3.17-1 gethostbyname() leak

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 :
>       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 Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                      
Red Hat, Inc.

Unsubscribe info:
Bug reporting:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]