From 1efecd965fe81d65e2763be4f43df2d8c4d8be44 Mon Sep 17 00:00:00 2001
From: Rod Sheeter <rsheeter@google.com>
Date: Wed, 14 Feb 2018 18:42:29 -0800
Subject: [PATCH] [subset] hmtx use copy writeable fn instead of direct memory

---
 src/hb-ot-hmtx-table.hh | 23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh
index 1368214d1..209c052b2 100644
--- a/src/hb-ot-hmtx-table.hh
+++ b/src/hb-ot-hmtx-table.hh
@@ -68,33 +68,18 @@ struct hmtxvmtx
   inline bool subset_update_header(hb_subset_plan_t *plan,
                                    unsigned int num_hmetrics) const
   {
-    /* alloc the new table */
-    size_t dest_sz = sizeof(H);
-    void *dest = (void *) calloc(dest_sz, 1);
-    if (unlikely(!dest))
-    {
-      return false;
-    }
-
     hb_blob_t *src_blob = OT::Sanitizer<H>().sanitize (plan->source->reference_table (H::tableTag));
-    unsigned int src_length;
-    const char *src_raw = hb_blob_get_data (src_blob, &src_length);
+    hb_blob_t *dest_blob = hb_blob_copy_writable_or_fail(src_blob);
     hb_blob_destroy (src_blob);
 
-    if (src_length != sizeof (H)) {
-      free (dest);
+    if (unlikely(!dest_blob)) {
       return false;
     }
-    memcpy(dest, src_raw, src_length);
 
-    H *table = (H *) dest;
+    unsigned int length;
+    H *table = (H *) hb_blob_get_data(dest_blob, &length);
     table->numberOfLongMetrics.set (num_hmetrics);
 
-    hb_blob_t *dest_blob = hb_blob_create ((const char *) dest,
-                                           dest_sz,
-                                           HB_MEMORY_MODE_READONLY,
-                                           dest,
-                                           free);
     bool result = hb_subset_plan_add_table (plan, H::tableTag, dest_blob);
     hb_blob_destroy (dest_blob);