[cff] Fix leak of cmap data

When `sfnt->load_face` succeeds it has already loaded any (optional)
cmap data. As a result, a subsequent call to `sfnt->load_cmap` will
overwrite the cmap data pointer with a new copy of the data but not free
the old, leading to a leak.

This is a fix for "* src/cff/cffobjs.c (cff_face_init): Better handling
of Type0 fonts.". This still allows the cmap to be missing but avoids
the leak by only calling `sfnt->load_cmap` when there is no `head`
table (the font data is not being loaded as OpenType/CFF).

* src/cff/cffobjs.c (cff_face_init): Fix leak

Fixes: #1306
master
Ben Wagner 3 months ago
parent 3f3e3de34e
commit 59320b2d3c
  1. 18
      src/cff/cffobjs.c

@ -537,8 +537,8 @@
sfnt_format = 1;
/* now, the font can be either an OpenType/CFF font, or an SVG CEF */
/* font; in the latter case it doesn't have a `head' table */
/* the font may be OpenType/CFF, SVG CEF, or sfnt/CFF; a `head' table */
/* implies OpenType/CFF, otherwise just look for an optional cmap */
error = face->goto_table( face, TTAG_head, stream, 0 );
if ( !error )
{
@ -550,13 +550,15 @@
if ( error )
goto Exit;
}
else
{
/* load the `cmap' table explicitly */
error = sfnt->load_cmap( face, stream );
/* load the `cmap' table explicitly */
error = sfnt->load_cmap( face, stream );
/* this may fail because CID-keyed fonts don't have a cmap */
if ( FT_ERR_NEQ( error, Table_Missing ) && FT_ERR_NEQ( error, Ok ) )
goto Exit;
/* this may fail because CID-keyed fonts don't have a cmap */
if ( FT_ERR_NEQ( error, Table_Missing ) && FT_ERR_NEQ( error, Ok ) )
goto Exit;
}
/* now load the CFF part of the file; */
/* give priority to CFF2 */

Loading…
Cancel
Save