diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index 805ac492c..733536153 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -246,16 +246,6 @@ struct hb_serialize_context_t Type *extend (Type &obj) { return extend_size (obj, obj.get_size ()); } /* Output routines. */ - template - Type *copy () const - { - assert (this->successful); - unsigned int len = this->head - this->start; - void *p = malloc (len); - if (p) - memcpy (p, this->start, len); - return reinterpret_cast (p); - } hb_bytes_t copy_bytes () const { assert (this->successful); @@ -267,13 +257,15 @@ struct hb_serialize_context_t return hb_bytes_t (); return hb_bytes_t ((char *) p, len); } + template + Type *copy () const + { return reinterpret_cast ((char *) copy_bytes ().arrayZ); } hb_blob_t *copy_blob () const { - assert (this->successful); - return hb_blob_create (this->start, - this->head - this->start, - HB_MEMORY_MODE_DUPLICATE, - nullptr, nullptr); + hb_bytes_t b = copy_bytes (); + return hb_blob_create (b.arrayZ, b.length, + HB_MEMORY_MODE_WRITABLE, + (char *) b.arrayZ, free); } public: /* TODO Make private. */