Merge pull request #828 from googlefonts/mem-fixes

[subset] Fix several memory leaks in subsetting.
This commit is contained in:
Garret Rieger 2018-02-23 17:59:08 -07:00 committed by GitHub
commit 7e5e1feb66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 11 deletions

View File

@ -602,7 +602,7 @@ struct cmap
+ 8 // 1 EncodingRecord
+ 16 // Format 12 header
+ 12 * groups.len; // SequentialMapGroup records
void *dest = calloc (dest_sz, 1);
void *dest = malloc (dest_sz);
if (unlikely (!dest)) {
DEBUG_MSG(SUBSET, nullptr, "Unable to alloc %lu for cmap subset output", (unsigned long) dest_sz);
return false;
@ -618,9 +618,11 @@ struct cmap
hb_blob_t *cmap_prime = hb_blob_create ((const char *)dest,
dest_sz,
HB_MEMORY_MODE_READONLY,
/* userdata */ nullptr,
dest,
free);
return hb_subset_plan_add_table (plan, HB_OT_TAG_cmap, cmap_prime);
bool result = hb_subset_plan_add_table (plan, HB_OT_TAG_cmap, cmap_prime);
hb_blob_destroy (cmap_prime);
return result;
}
struct accelerator_t

View File

@ -105,7 +105,7 @@ struct hmtxvmtx
/* alloc the new table */
size_t dest_sz = num_advances * 4
+ (gids.len - num_advances) * 2;
void *dest = (void *) calloc (dest_sz, 1);
void *dest = (void *) malloc (dest_sz);
if (unlikely (!dest))
{
return false;
@ -166,9 +166,11 @@ struct hmtxvmtx
hb_blob_t *result = hb_blob_create ((const char *)dest,
dest_sz,
HB_MEMORY_MODE_READONLY,
/* userdata */ nullptr,
dest,
free);
return hb_subset_plan_add_table (plan, T::tableTag, result);
bool success = hb_subset_plan_add_table (plan, T::tableTag, result);
hb_blob_destroy (result);
return success;
}
struct accelerator_t

View File

@ -234,6 +234,8 @@ hb_subset_glyf_and_loca (hb_subset_plan_t *plan,
use_short_loca,
glyf_prime,
loca_prime);
hb_blob_destroy (glyf_blob);
glyf.fini();
return result;

View File

@ -165,6 +165,7 @@ _populate_gids_to_retain (hb_face_t *face,
while (hb_set_next (all_gids_to_retain, &gid))
*(old_gids_sorted.push ()) = gid;
hb_set_destroy (all_gids_to_retain);
glyf.fini ();
cmap.fini ();
}

View File

@ -136,6 +136,9 @@ _hb_subset_face_data_destroy (void *user_data)
{
hb_subset_face_data_t *data = (hb_subset_face_data_t *) user_data;
for (int i = 0; i < data->tables.len; i++)
hb_blob_destroy (data->tables[i].blob);
data->tables.finish ();
free (data);
@ -260,14 +263,11 @@ _subset_table (hb_subset_plan_t *plan,
break;
default:
hb_blob_t *source_table = hb_face_reference_table(plan->source, tag);
if (likely(source_table))
{
if (likely (source_table))
result = hb_subset_plan_add_table(plan, tag, source_table);
}
else
{
result = false;
}
hb_blob_destroy (source_table);
break;
}
DEBUG_MSG(SUBSET, nullptr, "subset %c%c%c%c %s", HB_UNTAG(tag), result ? "ok" : "FAILED");