forked from firka/flutter
libtxt: fix leaks in Skia object reference counting (flutter/engine#4988)
Fixes https://github.com/flutter/flutter/issues/16526
This commit is contained in:
@@ -37,7 +37,7 @@ AssetFontStyleSet* AssetDataProvider::MatchFamily(
|
||||
if (found == registered_families_.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return &found->second;
|
||||
return SkRef(&found->second);
|
||||
}
|
||||
|
||||
void AssetDataProvider::RegisterTypeface(sk_sp<SkTypeface> typeface) {
|
||||
|
||||
@@ -31,7 +31,7 @@ SkTypeface* AssetFontStyleSet::createTypeface(int index) {
|
||||
if (index_cast >= typefaces_.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
return typefaces_[index_cast].get();
|
||||
return SkRef(typefaces_[index_cast].get());
|
||||
}
|
||||
|
||||
SkTypeface* AssetFontStyleSet::matchStyle(const SkFontStyle& pattern) {
|
||||
@@ -42,7 +42,7 @@ SkTypeface* AssetFontStyleSet::matchStyle(const SkFontStyle& pattern) {
|
||||
if (typeface->fontStyle() == pattern)
|
||||
return typeface.get();
|
||||
|
||||
return typefaces_[0].get();
|
||||
return SkRef(typefaces_[0].get());
|
||||
}
|
||||
|
||||
} // namespace txt
|
||||
|
||||
@@ -100,7 +100,7 @@ FontCollection::GetMinikinFontCollectionForFamily(const std::string& family) {
|
||||
}
|
||||
|
||||
for (sk_sp<SkFontMgr>& manager : GetFontManagerOrder()) {
|
||||
auto font_style_set = manager->matchFamily(family.c_str());
|
||||
sk_sp<SkFontStyleSet> font_style_set(manager->matchFamily(family.c_str()));
|
||||
if (font_style_set == nullptr || font_style_set->count() == 0) {
|
||||
continue;
|
||||
}
|
||||
@@ -111,8 +111,8 @@ FontCollection::GetMinikinFontCollectionForFamily(const std::string& family) {
|
||||
for (int i = 0, style_count = font_style_set->count(); i < style_count;
|
||||
++i) {
|
||||
// Create the skia typeface.
|
||||
auto skia_typeface =
|
||||
sk_ref_sp<SkTypeface>(font_style_set->createTypeface(i));
|
||||
sk_sp<SkTypeface> skia_typeface(
|
||||
sk_sp<SkTypeface>(font_style_set->createTypeface(i)));
|
||||
if (skia_typeface == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user