Skip to content

Fix memory leaks in FontLoaderMac #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/mac/FontLoaderMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ static String16 ToString16(CFStringRef str) {
String16 FontLoaderMac::fallback_font_for_characters(const String16& characters, int weight, bool italic) const {
CFStringRef str = CFStringCreateWithCharacters(kCFAllocatorDefault, reinterpret_cast<const UniChar*>(characters.data()), characters.length());
// Use Helvetica as our base font, go through its cascade list to find a system fallback that can display the given charachters
CTFontRef font = CTFontCreateForString(CTFontCreateWithName(CFSTR("Helvetica"), 12.0, NULL), str, {0, (CFIndex)characters.length()});
CTFontRef helveticaRef = CTFontCreateWithName(CFSTR("Helvetica"), 12.0, NULL);
CTFontRef font = CTFontCreateForString(helveticaRef, str, {0, (CFIndex)characters.length()});
CFStringRef family = CTFontCopyFamilyName(font);
String16 result = ToString16(family);

CFRelease(str);
CFRelease(helveticaRef);
CFRelease(font);

if (result.empty())
return fallback_font();
return result;
Expand Down Expand Up @@ -110,7 +116,7 @@ static bool Equals(const String16& a, const String16& b) {
if (!url)
return nullptr;

NSString* fontPath = [NSString stringWithString:[(__bridge NSURL *)url path]];
NSString* fontPath = [NSString stringWithString:[(NSURL *)CFBridgingRelease(url) path]];
CFRelease(descriptor);

ultralight::String16 filepath([fontPath UTF8String]);
Expand Down