Skip to content

Commit

Permalink
libtxt: fix leaks in Skia object reference counting (#4988)
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-simmons authored Apr 12, 2018
1 parent 0c74fc9 commit a530035
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion third_party/txt/src/txt/asset_data_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions third_party/txt/src/txt/asset_font_style_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
6 changes: 3 additions & 3 deletions third_party/txt/src/txt/font_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit a530035

Please sign in to comment.