-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Verify block is still alive before calling it in task callbacks #7054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
if (callback) { | ||
callback(metadata, self.error); | ||
} | ||
self->_fetcherCompletion = nil; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly curious, why the retain cycle is needed here? A comment on it would be useful to avoid such questions in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe to avoid multiple calls? I'm not sure, but either way, it seems outside the scope of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure! You just removed the warning suppression so I thought you know why it's actually needed :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the warning suppression because the warning suppression isn't needed :). Warnings don't get generated.
|
||
[fetcher beginFetchWithCompletionHandler:^(NSData *_Nullable data, NSError *_Nullable error) { | ||
weakSelf.fetcherCompletion(data, error); | ||
if (weakSelf.fetcherCompletion != nil) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unsafe--the object can be deallocated while the method is in progress. Calling a method does not retain self. You need to assign from weakSelf to a (new) strong reference and then check if that strong reference is nil.
Thanks @wilhuff |
Fix #7051
General case follow up to #3786