diff --git a/gfx/thebes/gfxDWriteFontList.cpp b/gfx/thebes/gfxDWriteFontList.cpp index 9552eb5f65f3..410ede63c896 100644 --- a/gfx/thebes/gfxDWriteFontList.cpp +++ b/gfx/thebes/gfxDWriteFontList.cpp @@ -855,13 +855,10 @@ bool gfxDWriteFontEntry::IsCJKFont() { mIsCJK = false; const uint32_t kOS2Tag = TRUETYPE_TAG('O', 'S', '/', '2'); - hb_blob_t* blob = GetFontTable(kOS2Tag); + gfxFontUtils::AutoHBBlob blob(GetFontTable(kOS2Tag)); if (!blob) { return mIsCJK; } - // |blob| is an owning reference, but is not RAII-managed, so it must be - // explicitly freed using |hb_blob_destroy| before we return. (Beware of - // adding any early-return codepaths!) uint32_t len; const OS2Table* os2 = @@ -879,7 +876,6 @@ bool gfxDWriteFontEntry::IsCJKFont() { mIsCJK = true; } } - hb_blob_destroy(blob); return mIsCJK; } diff --git a/gfx/thebes/gfxFT2FontList.cpp b/gfx/thebes/gfxFT2FontList.cpp index a215931e019a..f85b73758449 100644 --- a/gfx/thebes/gfxFT2FontList.cpp +++ b/gfx/thebes/gfxFT2FontList.cpp @@ -277,19 +277,20 @@ static void SetPropertiesFromFace(gfxFontEntry* aFontEntry, }; // Get the macStyle field from the 'head' table - hb_blob_t* blob = hb_face_reference_table(aFace, HB_TAG('h', 'e', 'a', 'd')); + gfxFontUtils::AutoHBBlob headBlob( + hb_face_reference_table(aFace, HB_TAG('h', 'e', 'a', 'd'))); unsigned int len; - const char* data = hb_blob_get_data(blob, &len); + const char* data = hb_blob_get_data(headBlob, &len); uint16_t style = 0; if (len >= sizeof(HeadTable)) { const HeadTable* head = reinterpret_cast(data); style = head->macStyle; } - hb_blob_destroy(blob); // Get the OS/2 table for weight & width fields - blob = hb_face_reference_table(aFace, HB_TAG('O', 'S', '/', '2')); - data = hb_blob_get_data(blob, &len); + gfxFontUtils::AutoHBBlob os2blob( + hb_face_reference_table(aFace, HB_TAG('O', 'S', '/', '2'))); + data = hb_blob_get_data(os2blob, &len); uint16_t os2weight = 400; float stretch = 100.0; if (len >= offsetof(OS2Table, fsType)) { @@ -300,7 +301,6 @@ static void SetPropertiesFromFace(gfxFontEntry* aFontEntry, stretch = kOS2WidthToStretch[os2width]; } } - hb_blob_destroy(blob); aFontEntry->mStyleRange = SlantStyleRange( (style & 2) ? FontSlantStyle::ITALIC : FontSlantStyle::NORMAL); @@ -362,12 +362,12 @@ nsresult FT2FontEntry::ReadCMAP(FontInfoData* aFontInfoData) { nsresult rv = NS_ERROR_NOT_AVAILABLE; uint32_t uvsOffset = 0; - if (hb_blob_t* cmapBlob = GetFontTable(TTAG_cmap)) { + gfxFontUtils::AutoHBBlob cmapBlob(GetFontTable(TTAG_cmap)); + if (cmapBlob) { unsigned int length; const char* data = hb_blob_get_data(cmapBlob, &length); rv = gfxFontUtils::ReadCMAP((const uint8_t*)data, length, *charmap, uvsOffset); - hb_blob_destroy(cmapBlob); } mUVSOffset.exchange(uvsOffset); @@ -439,11 +439,11 @@ hb_face_t* FT2FontEntry::CreateHBFace() const { if (mFilename[0] == '/') { // An absolute path means a normal file in the filesystem, so we can use // hb_blob_create_from_file to read it. - hb_blob_t* fileBlob = hb_blob_create_from_file(mFilename.get()); + gfxFontUtils::AutoHBBlob fileBlob( + hb_blob_create_from_file(mFilename.get())); if (hb_blob_get_length(fileBlob) > 0) { result = hb_face_create(fileBlob, mFTFontIndex); } - hb_blob_destroy(fileBlob); } else { // A relative path means an omnijar resource, which we may need to // decompress to a temporary buffer. @@ -462,11 +462,10 @@ hb_face_t* FT2FontEntry::CreateHBFace() const { cursor.Copy(&length); MOZ_ASSERT(length == item->RealSize(), "error reading font"); if (length == item->RealSize()) { - hb_blob_t* blob = + gfxFontUtils::AutoHBBlob blob( hb_blob_create((const char*)buffer, length, - HB_MEMORY_MODE_READONLY, buffer, free); + HB_MEMORY_MODE_READONLY, buffer, free)); result = hb_face_create(blob, mFTFontIndex); - hb_blob_destroy(blob); } } } @@ -1180,14 +1179,13 @@ void gfxFT2FontList::AppendFacesFromFontFile(const nsCString& aFileName, } } - hb_blob_t* fileBlob = hb_blob_create_from_file(aFileName.get()); + gfxFontUtils::AutoHBBlob fileBlob(hb_blob_create_from_file(aFileName.get())); if (hb_blob_get_length(fileBlob) > 0) { LOG(("reading font info via harfbuzz for %s", aFileName.get())); AppendFacesFromBlob(aFileName, aStdFile, fileBlob, 0 == statRetval ? aCache : nullptr, s.st_mtime, s.st_size); } - hb_blob_destroy(fileBlob); } void gfxFT2FontList::FindFontsInOmnijar(FontNameCache* aCache) { @@ -1374,10 +1372,9 @@ void gfxFT2FontList::AppendFacesFromOmnijarEntry(nsZipArchive* aArchive, return; } - hb_blob_t* blob = - hb_blob_create(buffer, bufSize, HB_MEMORY_MODE_READONLY, buffer, free); + gfxFontUtils::AutoHBBlob blob( + hb_blob_create(buffer, bufSize, HB_MEMORY_MODE_READONLY, buffer, free)); AppendFacesFromBlob(aEntryName, kStandard, blob, aCache, 0, bufSize); - hb_blob_destroy(blob); } // Called on each family after all fonts are added to the list; diff --git a/gfx/thebes/gfxFT2Utils.cpp b/gfx/thebes/gfxFT2Utils.cpp index 0918e5993cd7..94403c9dc195 100644 --- a/gfx/thebes/gfxFT2Utils.cpp +++ b/gfx/thebes/gfxFT2Utils.cpp @@ -131,8 +131,8 @@ void gfxFT2Utils::GetVariationInstances( if (!aMMVar) { return; } - hb_blob_t* nameTable = - aFontEntry->GetFontTable(TRUETYPE_TAG('n', 'a', 'm', 'e')); + gfxFontUtils::AutoHBBlob nameTable( + aFontEntry->GetFontTable(TRUETYPE_TAG('n', 'a', 'm', 'e'))); if (!nameTable) { return; } @@ -154,5 +154,4 @@ void gfxFT2Utils::GetVariationInstances( } aInstances.AppendElement(inst); } - hb_blob_destroy(nameTable); } diff --git a/gfx/thebes/gfxFontEntry.cpp b/gfx/thebes/gfxFontEntry.cpp index 5f520a19f2f2..649961aca384 100644 --- a/gfx/thebes/gfxFontEntry.cpp +++ b/gfx/thebes/gfxFontEntry.cpp @@ -656,7 +656,7 @@ tainted_opaque_gr gfxFontEntry::GrGetTable( rlbox::from_opaque(aName).unverified_safe_because( "This is only being used to index into a hashmap, which is robust " "for any value. No checks needed."); - hb_blob_t* blob = fontEntry->GetFontTable(fontTableKey); + gfxFontUtils::AutoHBBlob blob(fontEntry->GetFontTable(fontTableKey)); if (blob) { unsigned int blobLength; @@ -670,7 +670,6 @@ tainted_opaque_gr gfxFontEntry::GrGetTable( *t_aLen = blobLength; ret = rlbox::sandbox_const_cast(t_tableData); } - hb_blob_destroy(blob); } } diff --git a/gfx/thebes/gfxFontUtils.cpp b/gfx/thebes/gfxFontUtils.cpp index 1e0ba87586c1..02543607cd24 100644 --- a/gfx/thebes/gfxFontUtils.cpp +++ b/gfx/thebes/gfxFontUtils.cpp @@ -1171,11 +1171,10 @@ nsresult gfxFontUtils::GetFullNameFromSFNT(const uint8_t* aFontData, NS_ENSURE_TRUE(aLength > len && aLength - len >= dirEntry->offset, NS_ERROR_UNEXPECTED); - hb_blob_t* nameBlob = - hb_blob_create((const char*)aFontData + dirEntry->offset, len, - HB_MEMORY_MODE_READONLY, nullptr, nullptr); + AutoHBBlob nameBlob(hb_blob_create((const char*)aFontData + dirEntry->offset, + len, HB_MEMORY_MODE_READONLY, nullptr, + nullptr)); nsresult rv = GetFullNameFromTable(nameBlob, aFullName); - hb_blob_destroy(nameBlob); return rv; }