Re: Do I need to free() after gethostbyname()?
Re: Do I need to free() after gethostbyname()?
- Subject: Re: Do I need to free() after gethostbyname()?
- From: Allan Nathanson <email@hidden>
- Date: Wed, 29 Sep 2004 14:56:58 -0400
On Sep 29, 2004, at 2:44 PM, Justin Walker wrote:
On Sep 29, 2004, at 10:35, Dave Camp wrote:
I've got some leaks in my program and ObjectAlloc seems to show a
leak for every call to gethostbyname().
The man page for gethostbyname doesn't indicate I need to free the
pointer that is returned and a google on 'gethostbyname free' yields
some hits that indicate that on some systems the pointer is to a
static struct and does not need to be freed, and on others it is
malloc'd and does need to be freed
According to the man page, the values returned point to static
storage. On the other hand, the code (in the libinfo project) appears
to show dynamically allocated storage. I didn't follow all the twisty
little passages, so am just guessing about this.
In any case, a bug report might be in order (at least, for the man
page).
On Darwin, gethostbyname() returns a pointer to per-thread
[essentially-]static storage. You should not free() the returned name.
Of course, if a leak is being reported than maybe there's a bug in the
code.
- Allan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden