E539 Verify block is still alive before calling it in task callbacks by paulb777 · Pull Request #7054 · firebase/firebase-ios-sdk · GitHub
[go: up one dir, main page]

Skip to content

Conversation

paulb777
Copy link
Member

Fix #7051

General case follow up to #3786

@schmidt-sebastian schmidt-sebastian removed their assignment Nov 30, 2020
if (callback) {
callback(metadata, self.error);
}
self->_fetcherCompletion = nil;
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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 :)

Copy link
Member Author

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) {
Copy link
Contributor

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.

@paulb777
Copy link
Member Author

Thanks @wilhuff

@paulb777 paulb777 merged commit b4c77b6 into master Nov 30, 2020
@paulb777 paulb777 deleted the pb-fix7051 branch November 30, 2020 20:16
@firebase firebase locked and limited conversation to collaborators Dec 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EXC_BAD_ACCESS (KERN_INVALID_ADDRESS) with FIRStorageDownloadTask
5 participants
0