tmdvs/TDBadgedCell

Crash when TDBadgedCell is released on non-ARC environment

yoasha opened this issue · 0 comments

This is the current code:

- (void) setBadgeString:(NSString *)badgeString
{
    __badgeString = badgeString;
#if __has_feature(objc_arc)
    __badge.badgeString = [__badgeString copy];
#else
    __badge.badgeString = [[__badgeString copy] autorelease];
#endif
    [__badge setNeedsDisplay];
    [self layoutSubviews];
}

As you can see, the first line of the function is:

__badgeString = badgeString;

This is incorrect code in non ARC environment, as the __badgeString member variable is not retained, yet it is being released later on in the Dealloc() method.

Recommended fix:

- (void) setBadgeString:(NSString *)badgeString
{
#if __has_feature(objc_arc)
    __badgeString = badgeString;
    __badge.badgeString = [__badgeString copy];
#else
    [__badgeString release];
    __badgeString = [badgeString retain];
    __badge.badgeString = [[__badgeString copy] autorelease];
#endif
    [__badge setNeedsDisplay];
    [self layoutSubviews];
}