Re: Correct Order for CFRelease-ing CFNetwork Refs?
Re: Correct Order for CFRelease-ing CFNetwork Refs?
- Subject: Re: Correct Order for CFRelease-ing CFNetwork Refs?
- From: "Kyle Sluder" <email@hidden>
- Date: Tue, 1 Jul 2008 13:09:01 -0400
On Tue, Jul 1, 2008 at 9:09 AM, Jonathan Hohle <email@hidden> wrote:
> I recently wrote some code to retrieve data from an NTLM authenticated web
> server. As far as I can tell NTLM isn't supported at the Cocoa level, so I
> used CFNetwork to make the request. The example docs were clear and helpful,
> but I couldn't find anything on deallocating a CFHTTPAuthenticationRef.
There won't be any documentation regarding allocating and deallocating
most objects, because, like Cocoa, Core Foundation religiously follows
a memory management scheme known as the Create Rule.
> The example code saves off the CFHTTPAuthenticationRef for reuse, a pattern
> which I followed. In my -dealloc method, I was calling CFRelease with the
> request ref (which may or may not have an authentication ref applied to it),
> followed by CFRelease with the authentication ref. This consistently crashed
> with EXC_BAD_ACCESS. By chance, I switched the order, and now the code works
> without crashing.
How did you create your auth ref?
CFHTTPAuthenticationCreateFromResponse? It seems that you have
forgotten to CFRetain it (when you store it somewhere is the most
likely place) and freeing the request is releasing the auth ref which
is also being freed.
--Kyle Sluder
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden