AliSoftware / OHAttributedLabel

UILabel that supports NSAttributedString
https://github.com/AliSoftware/OHAttributedLabel/wiki
1.51k stars 344 forks source link

Potential leak in NSAttributedString+Attributes #173

Open rivera-ernesto opened 10 years ago

rivera-ernesto commented 10 years ago

Xcode 5 analyzer warns about a potential leak of currentFont in NSAttributedString+Attributes.m here.

OHAttributedLabel/Source/NSAttributedString+Attributes.m:276:7: Potential leak of an object stored into 'currentFont'

It seems that a simple CFRelease(currentFont) would fix it.

AliSoftware commented 10 years ago

Nice catch. But we can't simply CFRelease(currentFont) as it would crash in the case the previous line did return a non-nil CFFont (if we don't enter the if)…

To avoid a crash here if we add a CFRelease later, we need to CFRetain it when it's non-nil (in an else condition corresponding to this if statement), so that the CFRelease will balance the retain count in both situations (either when we get it from the attribute then retain it, or if we CTFontCreate it directly)