From 26b9670d996465161964bf1a0a7c4ecf2bf2212e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 28 Jun 2020 14:52:15 -0700 Subject: [PATCH] [ft] Better handle allocation failures Fixes https://github.com/harfbuzz/harfbuzz/issues/2513 --- src/hb-ft.cc | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/hb-ft.cc b/src/hb-ft.cc index 073fd4b02..2680873c2 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -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,