cast IMP of sendAsynchronousRequest:queue:completionHandler: to a typed function pointer, preventing ARC from calling objc_retain() on arbitrary register contents

Merged
#3 · Created  · Last updated

Merged pull request

Merged in fightingmonk/nsurlconnectionvcr/fix-arc-retain (pull request #3)

ad385a9·Author: ·Closed by: ·2014-02-19

Description

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.

0 attachments

0 comments

Loading commits...