Skip to content
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

Fix a crash when time's selecter set self to nil, cause to a zombie. #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Hydra2050
Copy link

When timerFired invoking , if self is setting to nil when self.selector is called, self will be a zombie.

// We're not worried about this warning because the selector we're calling doesn't return a +1 object.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    [self.target performSelector:self.selector withObject:self];
#pragma clang diagnostic pop

if (!self.repeats)
{
    [self invalidate];
}

So, make a strong self object , make the retaincount +1, make sure self will not dealloc within this scope.

MSWeakTimer *strongSelf = self;
// We're not worried about this warning because the selector we're calling doesn't return a +1 object.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    [self.target performSelector:self.selector withObject:self];
#pragma clang diagnostic pop

if (!strongSelf.repeats)
{
    [strongSelf invalidate];
}

@JaviSoto
Copy link
Contributor

Sorry for the super late response, I never saw this until now!

Hmmm do you have a test that shows that bug? And that it proves that this fixes it? That would be useful.
AFAIK if self is deallocating, increasing its retain count by acquiring a strong reference would also crash...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants