delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/12/10/10:36:23

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
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 10:36:04 -0500 (EST)
From: Igor Pechtchanski <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: Noel Gordon <noelg AT blueskyinternet DOT com DOT au>
cc: cygwin AT cygwin DOT com
Subject: Re: cygwin 1.3.17-1 gethostbyname() leak
In-Reply-To: <01a001c2a029$0d9950d0$3492fea9@NOELG>
Message-ID: <Pine.GSO.4.44.0212101024110.12239-100000@slinky.cs.nyu.edu>
Importance: Normal
MIME-Version: 1.0

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?
>
> /*-----------------------------------------------------------*/
>
> #include <netdb.h>
> #include <stdio.h>
>
> int main()
> {
>   struct hostent *host;
>
>   while ( 1 )
>   {
>     if ( ( host = gethostbyname( "localhost" ) ) != NULL )
>       printf( "gethostbyname(): %s\n", host->h_name );
>   }
> }

Noel,

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.
	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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019