Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a530035

Browse files
libtxt: fix leaks in Skia object reference counting (#4988)
Fixes flutter/flutter#16526
1 parent 0c74fc9 commit a530035

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎third_party/txt/src/txt/asset_data_provider.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ AssetFontStyleSet* AssetDataProvider::MatchFamily(
3737
if (found == registered_families_.end()) {
3838
return nullptr;
3939
}
40-
return &found->second;
40+
return SkRef(&found->second);
4141
}
4242

4343
void AssetDataProvider::RegisterTypeface(sk_sp<SkTypeface> typeface) {

‎third_party/txt/src/txt/asset_font_style_set.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ SkTypeface* AssetFontStyleSet::createTypeface(int index) {
3131
if (index_cast >= typefaces_.size()) {
3232
return nullptr;
3333
}
34-
return typefaces_[index_cast].get();
34+
return SkRef(typefaces_[index_cast].get());
3535
}
3636

3737
SkTypeface* AssetFontStyleSet::matchStyle(const SkFontStyle& pattern) {
@@ -42,7 +42,7 @@ SkTypeface* AssetFontStyleSet::matchStyle(const SkFontStyle& pattern) {
4242
if (typeface->fontStyle() == pattern)
4343
return typeface.get();
4444

45-
return typefaces_[0].get();
45+
return SkRef(typefaces_[0].get());
4646
}
4747

4848
} // namespace txt

‎third_party/txt/src/txt/font_collection.cc‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ FontCollection::GetMinikinFontCollectionForFamily(const std::string& family) {
100100
}
101101

102102
for (sk_sp<SkFontMgr>& manager : GetFontManagerOrder()) {
103-
auto font_style_set = manager->matchFamily(family.c_str());
103+
sk_sp<SkFontStyleSet> font_style_set(manager->matchFamily(family.c_str()));
104104
if (font_style_set == nullptr || font_style_set->count() == 0) {
105105
continue;
106106
}
@@ -111,8 +111,8 @@ FontCollection::GetMinikinFontCollectionForFamily(const std::string& family) {
111111
for (int i = 0, style_count = font_style_set->count(); i < style_count;
112112
++i) {
113113
// Create the skia typeface.
114-
auto skia_typeface =
115-
sk_ref_sp<SkTypeface>(font_style_set->createTypeface(i));
114+
sk_sp<SkTypeface> skia_typeface(
115+
sk_sp<SkTypeface>(font_style_set->createTypeface(i)));
116116
if (skia_typeface == nullptr) {
117117
continue;
118118
}

0 commit comments

Comments
 (0)