memory leak in gethostbyaddr() ?

Gareth Pearce tilps@hotmail.com
Mon Sep 2 22:59:00 GMT 2002



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



More information about the Cygwin mailing list