Releasing CFHost
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