• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Do I need to free() after gethostbyname()?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Do I need to free() after gethostbyname()?


  • Subject: Re: Do I need to free() after gethostbyname()?
  • From: Justin Walker <email@hidden>
  • Date: Wed, 29 Sep 2004 12:15:14 -0700


On Sep 29, 2004, at 11:56, Allan Nathanson wrote:


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.

Thanks for clarifying that, Allan. Guess I gave up on the twisty little passages too soon.


j

--
Justin C. Walker, Curmudgeon-At-Large *
Institute for General Semantics | "Weaseling out of things is what
| separates us from the animals.
| Well, except the weasel."
| - Homer J Simpson
*--------------------------------------*-------------------------------*


_______________________________________________
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


References: 
 >Do I need to free() after gethostbyname()? (From: Dave Camp <email@hidden>)
 >Re: Do I need to free() after gethostbyname()? (From: Justin Walker <email@hidden>)
 >Re: Do I need to free() after gethostbyname()? (From: Allan Nathanson <email@hidden>)

  • Prev by Date: Re: Do I need to free() after gethostbyname()?
  • Next by Date: Re: Do I need to free() after gethostbyname()?
  • Previous by thread: Re: Do I need to free() after gethostbyname()?
  • Next by thread: Re: Do I need to free() after gethostbyname()?
  • Index(es):
    • Date
    • Thread