• 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: CoreFoundation socket leak?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CoreFoundation socket leak?


  • Subject: Re: CoreFoundation socket leak?
  • From: Glenn Anderson <email@hidden>
  • Date: Sat, 26 Oct 2002 13:32:32 +1300

When creating a listening socket using the following call:

socketRef = CFSocketCreateWithSocketSignature(NULL, &signature, kCFSocketAcceptCallBack, MCFSocketCallback, &socketContext);
if (socketRef != NULL)
{
}

But the bind fails because another process is currently using the port, the file handle seems to be leaked.

The returned socketRef is NULL, so I can't call CFSocketinvalidate to clean it up, but lsof shows:

CSPRelay 11408 mlaster 16u inet 0x039cfd1c 0t0 TCP *:* (CLOSED)
CSPRelay 11408 mlaster 17u inet 0x03887d1c 0t0 TCP *:5678 (LISTEN)

The 16u handle was from a failed attempt, and the 17u handle was from the second time I called it after freeing up port 5678.

Is this a bug in CoreFoundation, or is there something I need to do to get rid of sockets that failed to bind?

I would call it a bug, but I can think of a couple of ways you should be able to easily work around it. You could use CFSocketCreate followed by CFSocketSetAddress, and if CFSocketSetAddress fails you should still be able to use CFSocketinvalidate. Alternatively you could use socket, bind, listen followed by CFSocketCreateWithNative, if the bind or listen fails, you can just call close.

Glenn.
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: CoreFoundation socket leak?
      • From: Quinn <email@hidden>
References: 
 >CoreFoundation socket leak? (From: Mike Laster <email@hidden>)

  • Prev by Date: CoreFoundation socket leak?
  • Next by Date: Re: CoreFoundation socket leak?
  • Previous by thread: CoreFoundation socket leak?
  • Next by thread: Re: CoreFoundation socket leak?
  • Index(es):
    • Date
    • Thread