From 0775bc0f7a59241456142b48abced75fd3db5a42 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 14 Feb 2018 16:37:35 -0800 Subject: [PATCH] [subset] Fix hhea subsetting and clean up some memory leaks. --- src/hb-ot-hmtx-table.hh | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index e69f9ea4..1368214d 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -76,26 +76,29 @@ struct hmtxvmtx return false; } - hb_blob_t *src_blob = OT::Sanitizer().sanitize (plan->source->reference_table (T::tableTag)); - if (unlikely(!src_blob)) - { - free(dest); - return false; - } + hb_blob_t *src_blob = OT::Sanitizer().sanitize (plan->source->reference_table (H::tableTag)); unsigned int src_length; - const char *src_raw = hb_blob_get_data(src_blob, &src_length); + const char *src_raw = hb_blob_get_data (src_blob, &src_length); + hb_blob_destroy (src_blob); + if (src_length != sizeof (H)) { + free (dest); + return false; + } memcpy(dest, src_raw, src_length); H *table = (H *) dest; - table->numberOfLongMetrics.set(num_hmetrics); + table->numberOfLongMetrics.set (num_hmetrics); - hb_blob_t *dest_blob = hb_blob_create ((const char *)dest, + hb_blob_t *dest_blob = hb_blob_create ((const char *) dest, dest_sz, HB_MEMORY_MODE_READONLY, - /* userdata */ nullptr, + dest, free); - return hb_subset_plan_add_table(plan, H::tableTag, dest_blob); + bool result = hb_subset_plan_add_table (plan, H::tableTag, dest_blob); + hb_blob_destroy (dest_blob); + + return result; } inline bool subset (hb_subset_plan_t *plan) const -- GitLab