From: Rod Sheeter Date: Tue, 21 May 2019 03:40:55 +0000 (-0700) Subject: [subset] Fix memory leak caused by failure to cleanup glyf accelerator X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3a43603ecea2c349f58396e103a52948776681e0;p=platform%2Fupstream%2FlibHarfBuzzSharp.git [subset] Fix memory leak caused by failure to cleanup glyf accelerator --- diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index c9b9cf4..4d45a93 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -148,39 +148,49 @@ struct glyf glyf *glyf_prime = c->serializer->start_embed (); if (unlikely (!glyf_prime)) return_trace (false); - OT::glyf::accelerator_t glyf; - glyf.init (c->plan->source); - // Byte region(s) per glyph to output // unpadded, hints removed if so requested // If we fail to process a glyph we produce an empty (0-length) glyph hb_vector_t glyphs; - + hb_range (c->plan->num_output_glyphs ()) + _populate_subset_glyphs (c->plan, &glyphs); + + glyf_prime->serialize (c->serializer, hb_iter (glyphs), c->plan); + + hb_vector_t padded_offsets; + + hb_iter (glyphs) + | hb_map ([&] (const SubsetGlyph& _) { return _.padded_size(); }) + | hb_sink (padded_offsets); + + _add_loca_and_head (c->plan, hb_iter (padded_offsets)); + + return_trace (true); + } + + template + void + _populate_subset_glyphs (const hb_subset_plan_t * plan, + hb_vector_t * glyphs /* OUT */) const + { + OT::glyf::accelerator_t glyf; + glyf.init (plan->source); + + + hb_range (plan->num_output_glyphs ()) | hb_map ([&] (hb_codepoint_t new_gid) { SubsetGlyph subset_glyph; subset_glyph.new_gid = new_gid; // should never fail: all old gids should be mapped - if (!c->plan->old_gid_for_new_gid (new_gid, &subset_glyph.old_gid)) return subset_glyph; + if (!plan->old_gid_for_new_gid (new_gid, &subset_glyph.old_gid)) return subset_glyph; subset_glyph.source_glyph = glyf.bytes_for_glyph ((const char *) this, subset_glyph.old_gid); - if (c->plan->drop_hints) subset_glyph.drop_hints (glyf); + if (plan->drop_hints) subset_glyph.drop_hints (glyf); else subset_glyph.dest_start = subset_glyph.source_glyph; return subset_glyph; }) | hb_sink (glyphs); - glyf_prime->serialize (c->serializer, hb_iter (glyphs), c->plan); - - hb_vector_t padded_offsets; - + hb_iter (glyphs) - | hb_map ([&] (const SubsetGlyph& _) { return _.padded_size(); }) - | hb_sink (padded_offsets); - - _add_loca_and_head (c->plan, hb_iter (padded_offsets)); - - return_trace (true); + glyf.fini(); } static void