Fix memory management for static block variables in UIAlertView+MKBlockAdditions #5

Open
wants to merge 4 commits into
from

2 participants

@albertodebortoli

If objects referenced in the blocks are deallocated, in the next invocation of alertViewWithTitle:message:cancelButtonTitle:otherButtonTitles:onDismiss:onCancel: block arguments still reference to deallocated instances causing crash.
Fix the case if more than one UIAlertView is shown using block-based category method.
Add thread safety.

@drewish drewish commented on the diff Aug 13, 2012
MKAdditions/UIAlertView+MKBlockAdditions.m
@@ -70,6 +70,11 @@ + (void)alertView:(UIAlertView*) alertView didDismissWithButtonIndex:(NSInteger)
{
_dismissBlock(buttonIndex - 1); // cancel button is button 0
}
+
+ [_cancelBlock release];
@drewish
drewish added a line comment Aug 13, 2012

I'm getting errors on these lines:

UIAlertView+MKBlockAdditions.m:108:6: Use of undeclared identifier '_cancelBlock'
UIAlertView+MKBlockAdditions.m:109:5: Unknown type name '_cancelBlock'; did you mean 'CancelBlock'?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@drewish

I think that should probably be:

[alertView.cancelBlock release];
alertView.cancelBlock = nil;
[alertView.dismissBlock release];
alertView.dismissBlock = nil;
@drewish

Yeah so it looks like pull request #7 made those into dynamic properties. I'm not sure if your change is still necessary but it should probably become something more like what I showed above.

@drewish

Okay I rebased your commit and fixed that: drewish@1994aa5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment