• 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
Releasing CFHost
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Releasing CFHost


  • Subject: Releasing CFHost
  • From: Rick Mann <email@hidden>
  • Date: Wed, 29 Jun 2011 14:21:56 -0700

Hi. I have some code that looks like this:

{
    CFHostRef host = CFHostCreateWithName(kCFAllocatorDefault, (CFStringRef) inHostName);

    CFHostClientContext     ctx = { 0 };
    ctx.info = self;
    CFHostSetClient(host, hostResolveCallback, &ctx);
    CFHostScheduleWithRunLoop(host, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);

    CFStreamError streamError;
    bool success = CFHostStartInfoResolution(host, kCFHostAddresses, &streamError);
    if (!success)
    {

        if (host != NULL)
        {
            CFRelease(host);
        }

        if ([mDelegate respondsToSelector: @selector(sntp:didFailWithError:)])
        {
            NSError* err = [NSError errorWithDomain: @"somedomain" code: streamError.error userInfo: nil];
            [self performSelectorOnMainThread: @selector(reportError:) withObject: err waitUntilDone: NO];
        }
    }

    return true;
}

The static analyzer complains about a possible leak, because I don't free the CFHostRef every time. But since I'm starting an operation that uses it. I'm not sure if CFHostScheduleWithRunLoop() or CFHostStartInfoResolution() retain the CFHostRef or not (the docs don't say either way).

Should I always release it? I do release it when the operation completes.

--
Rick

 _______________________________________________
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

  • Prev by Date: Re: URL filtering / IP Filter NKE
  • Previous by thread: Re: Tweaking TCP windowsize
  • Index(es):
    • Date
    • Thread