Skip to content

Commit f6dee2c

Browse files
authored
Fix memory leak in MTFont (#175)
1 parent ebc2043 commit f6dee2c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

iosMath/render/MTFont.m

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ - (instancetype)initFontWithName:(NSString *)name size:(CGFloat)size
3333
NSBundle* bundle = [MTFont fontBundle];
3434
NSString* fontPath = [bundle pathForResource:name ofType:@"otf"];
3535
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithFilename(fontPath.UTF8String);
36-
self.defaultCGFont = CGFontCreateWithDataProvider(fontDataProvider);
36+
_defaultCGFont = CGFontCreateWithDataProvider(fontDataProvider);
3737
CFRelease(fontDataProvider);
3838

39-
self.ctFont = CTFontCreateWithGraphicsFont(self.defaultCGFont, size, nil, nil);
39+
_ctFont = CTFontCreateWithGraphicsFont(self.defaultCGFont, size, nil, nil);
4040

4141
NSString* mathTablePlist = [bundle pathForResource:name ofType:@"plist"];
4242
NSDictionary* dict = [NSDictionary dictionaryWithContentsOfFile:mathTablePlist];
@@ -77,11 +77,11 @@ - (MTFont *)copyFontWithSize:(CGFloat)size
7777
{
7878
MTFont* copyFont = [[[self class] alloc] init];
7979
copyFont.defaultCGFont = self.defaultCGFont;
80-
// Retain the font as we are adding another reference to it.
81-
CGFontRetain(copyFont.defaultCGFont);
82-
copyFont.ctFont = CTFontCreateWithGraphicsFont(self.defaultCGFont, size, nil, nil);
80+
CTFontRef newCtFont = CTFontCreateWithGraphicsFont(self.defaultCGFont, size, nil, nil);
81+
copyFont.ctFont = newCtFont;
8382
copyFont.rawMathTable = self.rawMathTable;
8483
copyFont.mathTable = [[MTFontMathTable alloc] initWithFont:copyFont mathTable:copyFont.rawMathTable];
84+
CFRelease(newCtFont);
8585
return copyFont;
8686
}
8787

0 commit comments

Comments
 (0)