Sourceware Bugzilla – Bug 156
Info for gethostbyname_r doesn't say when temp buffer can be freed
Last modified: 2013-10-08 19:39:59 UTC
The info page for gethostbyname_r describes the function and gives an
example, but says nothing about when the "temporary" buffer passed via the BUF
parameter can be freed. I made the mistake of freeing it shortly after the
call, which works for me 99% of the time but failed in a hard-to-debug way when
my code tried to look up "localhost". I think that some of the pointers
(h_addr_list?) in the returned hostent struct point into this "temporary" space.
In many applications it will not be acceptable to allow this memory to leak (the
example code allocates at least 1k for each call). I suggest adding a line as
follows, but would appreciate it if someone could confirm that this is actually
"The buffer passed as the BUF parameter can be freed only once the caller has
finished with the result hostent struct, or has copied it including all the
other memory that it points to."
Appologies if I am missing something....
(I'm using glibc 2.3.2 on Debian Testing)
updated version, still pending post-2.3.6
Created attachment 7029 [details]
Patch adds the documentation for buffer in socket.texi
Added the statement in documentation to manual.socket.texi according to BZ156
I understand that some of you were waiting for the copyright assignment. As it is now done, could I get some feedback on this patch?
Fixed at 0b894d5e455e5242163c283c54a6d6ec2935927d.