OHAttributedLabel icon indicating copy to clipboard operation
OHAttributedLabel copied to clipboard

Potential leak in NSAttributedString+Attributes

Open rivera-ernesto opened this issue 12 years ago • 1 comments

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.

rivera-ernesto avatar Jan 17 '14 08:01 rivera-ernesto

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)

AliSoftware avatar Jan 17 '14 19:01 AliSoftware