From 6e7602c1049a1b409c1db61ac2dfa2d2b57a170d Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Thu, 28 Nov 2019 08:43:00 +0330 Subject: [PATCH] [ot-glyph] Fix leaks --- src/hb-ot-glyph.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/hb-ot-glyph.cc b/src/hb-ot-glyph.cc index 15c06dbdf..36686ce2c 100644 --- a/src/hb-ot-glyph.cc +++ b/src/hb-ot-glyph.cc @@ -103,6 +103,10 @@ void hb_ot_glyph_path_destroy (hb_ot_glyph_path_t *path) { if (!hb_object_destroy (path)) return; + + if (path->destroy) path->destroy (path->user_data); + + free (path); } struct _hb_ot_glyph_path_vectors @@ -146,7 +150,11 @@ hb_ot_glyph_path_create_from_font (hb_font_t *font, hb_codepoint_t glyph) { _hb_ot_glyph_path_vectors *user_data = (_hb_ot_glyph_path_vectors *) malloc (sizeof (_hb_ot_glyph_path_vectors)); - if (unlikely (!user_data->init ())) return hb_ot_glyph_path_empty (); + if (unlikely (!user_data || !user_data->init ())) + { + free (user_data); + return hb_ot_glyph_path_empty (); + } hb_vector_t &coords = *user_data->coords; hb_vector_t &commands = *user_data->commands; @@ -161,7 +169,12 @@ hb_ot_glyph_path_create_from_font (hb_font_t *font, hb_codepoint_t glyph) assert (coords.length % 2 == 0); /* coords pairs, should be an even number */ - if (unlikely (!ret)) return hb_ot_glyph_path_empty (); + if (unlikely (!ret)) + { + user_data->fini (); + free (user_data); + return hb_ot_glyph_path_empty (); + } return hb_ot_glyph_path_create (coords.arrayZ, coords.length, commands.arrayZ, commands.length, user_data, (hb_destroy_func_t) _hb_ot_glyph_path_free_vectors);