Mail Archives: cygwin/2005/03/16/13:12:22
> The problem is that autossh is freeing the return value of
> gethostbyname(). I can't find any reference which says that is a
> acceptable thing to do. It certainly screws up cygwin, and I can't
> think of any way to avoid having it screw up cygwin. Maybe it won't
> screw up other systems since they may not malloc the return value of
> gethostbyname. I dunno.
OK. (hangs head) I have to take the blame for this, because as it
happens I contributed that bit of code. Forgive my simplicity on this
point, but it seemed like good memory heigene-- free up the memory that
gethostbyname() allocated, once I was done with it. Looking back now at
the man page for gethostbyname() (in Linux, there's no Cygwin man page
AFAIK), it seems unclear on this point: the NOTES section says "The
functions gethostbyname() and gethostbyaddr() *may* return pointers to
static data, which may be overwritten by later calls." (emphasis added)
This may have been a dumb mistake, or not. Obviously if the memory is
static, I shouldn't free() it, but the docs are unclear about whether it
is or not. Should I infer that I should not free() memory allocated by
a function that I call unless the man page specifically says to? Or
just that it's best not to free() it if it might be static? This seems
like a complicated issue and any pointers for this journeyman network
programmer would be welcome. Probably OT for this list, though.
> I haven't run an exhaustive test, but the patch below seems to fix this
> problem.
Confirmed, it fixes my crash here with cygwin1.dll snapshot of 2005-Mar-
11.
> Could the autossh maintainer look into getting this applied upstream?
Done. I'll release a new version shortly.
Andrew.
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -