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: memory leak in gethostbyaddr() ?


    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.


Send and receive Hotmail on your mobile device:

Unsubscribe info:
Bug reporting:

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