[ft] release FT_Library reference on face-creation error paths (#6307)

reference_ft_library() returns an owned FT_Library reference that the
success paths hand to the FT_Face finalizer or the blob user-data
destructor. Four early returns in hb_ft_face_create_from_file_or_fail,
hb_ft_face_create_from_blob_or_fail and hb_ft_font_set_funcs returned
without releasing it, pinning the static library on invalid input and
OOM. Release it via destroy_ft_library() on each path.
This commit is contained in:
nussaibah shaikh authored and GitHub committed 2026-10-01 13:33:09 -06:00
1 parent e6d5454350
commit a4c13fc007
2 files changed
+28

No files matched your search

+8
View File
@@ -1681,7 +1681,10 @@ hb_ft_face_create_from_file_or_fail (const char *file_name,
file_name,
index,
&ft_face)))
{
destroy_ft_library (ft_library);
return nullptr;
}
FT_Reference_Face (ft_face);
hb_face_t *face = hb_ft_face_create (ft_face, _hb_ft_face_destroy_static);
@@ -1742,7 +1745,10 @@ hb_ft_face_create_from_blob_or_fail (hb_blob_t *blob,
blob_size,
index,
&ft_face)))
{
destroy_ft_library (ft_library);
return nullptr;
}
FT_Reference_Face (ft_face);
hb_face_t *face = hb_ft_face_create (ft_face, _hb_ft_face_destroy_static);
@@ -1836,6 +1842,7 @@ hb_ft_font_set_funcs (hb_font_t *font)
&ft_face)))
{
hb_blob_destroy (blob);
destroy_ft_library (ft_library);
DEBUG_MSG (FT, font, "FT_New_Memory_Face() failed");
return;
}
@@ -1852,6 +1859,7 @@ hb_ft_font_set_funcs (hb_font_t *font)
{
DEBUG_MSG (FT, font, "hb_blob_set_user_data() failed");
_hb_ft_face_destroy_static (ft_face);
destroy_ft_library (ft_library);
return;
}
+20
View File
@@ -296,6 +296,25 @@ test_native_ft_set_funcs_stream_face_no_deadlock (void)
cleanup_freetype ();
}
static void
test_native_ft_create_invalid_blob_no_leak (void)
{
/* The error path of hb_ft_face_create_from_blob_or_fail() must release the
* FT_Library reference it took from reference_ft_library(); otherwise the
* static library is pinned and leaks. Drive the failing path repeatedly so
* LeakSanitizer flags any unbalanced reference. */
static const char junk[] = "this is not a valid font blob at all";
for (unsigned int i = 0; i < 16; i++)
{
hb_blob_t *blob = hb_blob_create (junk, sizeof (junk),
HB_MEMORY_MODE_READONLY, NULL, NULL);
hb_face_t *face = hb_ft_face_create_from_blob_or_fail (blob, 0);
g_assert_null (face);
hb_blob_destroy (blob);
}
}
static gpointer
create_static_ft_faces (gpointer data)
{
@@ -350,6 +369,7 @@ main (int argc, char **argv)
hb_test_add (test_native_ft_set_funcs_preserves_load_flags);
hb_test_add (test_native_ft_set_funcs_stream_face_no_deadlock);
hb_test_add (test_native_ft_glyph_name_zero_size_probe);
hb_test_add (test_native_ft_create_invalid_blob_no_leak);
hb_test_add (test_static_ft_library_multithreaded);
return hb_test_run ();