cast IMP of sendAsynchronousRequest:queue:completionHandler: to a typed function pointer, preventing ARC from calling objc_retain() on arbitrary register contents
Jonathan Karon
Branch: fightingmonk/nsurlconnectionvcr:fix-arc-retain
Branch: martijnthe/nsurlconnectionvcr:master
Merged
Merged pull request
Merged in fightingmonk/nsurlconnectionvcr/fix-arc-retain (pull request #3)
When compiled with ARC, the return value from invoking origImps[X] is passed into objc_retain() because IMP is assumed to return an id value. For [NSURLConnection alloc] and [NSURLConnection sendSynchronousRequest:returningResponse:error:] this is correct behavior. [NSURLConnection sendAsynchronousRequest:queue:completionHandler:] however returns void. In this case, ARC's auto-generated objc_retain() is passed in a junk pointer to whatever was hanging around in the retval register, causing a crash.
This commit casts the IMP to a strongly typed function pointer that has a void return type, which gives the compiler enough information to suppress the generation of an objc_retain() call on the retval.