delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/09/03/01:59:21

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-Originating-IP: [129.78.64.17]
From: "Gareth Pearce" <tilps AT hotmail DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: memory leak in gethostbyaddr() ?
Date: Tue, 03 Sep 2002 05:59:08 +0000
Mime-Version: 1.0
Message-ID: <F211UHHxg0zCOYB8jdG00000c3d@hotmail.com>
X-OriginalArrivalTime: 03 Sep 2002 05:59:10.0691 (UTC) FILETIME=[05CFBB30:01C2530F]


>Hi!
>
>     I'm use gethostbyaddr() for name resolving. But when I'm call
>gethostbyaddr() many times, the memory, allocated by the program is growing
>(see attach). Why?

Hmm I thought this would be an obvious thing - its returning a pointer to 
memory you didnt give it so therefore your supposed to clean up.  However 
this is not always the case so I thought I would check SUS ... and I was 
supprised to find that it was specifically ambiguous??  I fail to see how a 
specification can get away with saying the return 'Might' point to static 
memory.  But indeed it does... wierd.  and SUSv3 says that gethostbyaddr is 
obsolete and getaddrinfo is recommend to be used instead (which looks like 
it Doesnt use static memory so your responsible for cleaning it up).
(not using static memory is good in a way, dont have to worry about multiple 
calls or threads causing significant problems)

So I suspect (but havent confirmed :P) that cygwin takes the 'doesnt use 
static memory' path available in the specification, and you just need to 
delete(free) it.
Not hard to test, it will almost certainly crash very quickly if its using 
static memory and you start freeing it inside the loop.

Gareth

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


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