1. Martijn The
  2. NSURLConnectionVCR

Pull requests

#3 Merged
Repository
fightingmonk
Branch
fix-arc-retain
Repository
martijnthe
Branch
master

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

Author
  1. Jonathan Karon
Reviewers
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.

  • Learn about pull requests

Comments (0)