[ft] Better handle allocation failures

Fixes https://github.com/harfbuzz/harfbuzz/issues/2513
This commit is contained in:
Behdad Esfahbod 2020-06-28 14:52:15 -07:00
parent 26111a11ad
commit 26b9670d99

View File

@ -92,9 +92,7 @@ static hb_ft_font_t *
_hb_ft_font_create (FT_Face ft_face, bool symbol, bool unref)
{
hb_ft_font_t *ft_font = (hb_ft_font_t *) calloc (1, sizeof (hb_ft_font_t));
if (unlikely (!ft_font))
return nullptr;
if (unlikely (!ft_font)) return nullptr;
ft_font->lock.init ();
ft_font->ft_face = ft_face;
@ -120,9 +118,6 @@ _hb_ft_font_destroy (void *data)
{
hb_ft_font_t *ft_font = (hb_ft_font_t *) data;
if (unlikely (!ft_font))
return;
ft_font->advance_cache.fini ();
if (ft_font->unref)
@ -623,9 +618,12 @@ _hb_ft_font_set_funcs (hb_font_t *font, FT_Face ft_face, bool unref)
{
bool symbol = ft_face->charmap && ft_face->charmap->encoding == FT_ENCODING_MS_SYMBOL;
hb_ft_font_t *ft_font = _hb_ft_font_create (ft_face, symbol, unref);
if (unlikely (!ft_font)) return;
hb_font_set_funcs (font,
_hb_ft_get_font_funcs (),
_hb_ft_font_create (ft_face, symbol, unref),
ft_font,
_hb_ft_font_destroy);
}
@ -833,9 +831,6 @@ hb_ft_font_changed (hb_font_t *font)
hb_ft_font_t *ft_font = (hb_ft_font_t *) font->user_data;
if (unlikely (!ft_font))
return;
FT_Face ft_face = ft_font->ft_face;
hb_font_set_scale (font,