* include/freetype/internal/services/svpscmap.h, src/cff/cffcmap.c,

src/psaux/t1cmap.c, src/psnames/psmodule.c: Fix for the memory
        leak described in bug #16759.

        We change 'ps_unicodes_init' so that it also takes a 'free_glyph_name'
        callback to release the glyph names returned by 'get_glyph_name'
This commit is contained in:
David Turner 2006-06-06 08:14:14 +00:00
parent d724f20e05
commit 457b4a81a1
5 changed files with 50 additions and 15 deletions

View File

@ -1,3 +1,13 @@
2006-06-06 David Turner <david@freetype.org>
* include/freetype/internal/services/svpscmap.h, src/cff/cffcmap.c,
src/psaux/t1cmap.c, src/psnames/psmodule.c: Fix for the memory
leak described in bug #16759.
We change 'ps_unicodes_init' so that it also takes a 'free_glyph_name'
callback to release the glyph names returned by 'get_glyph_name'
2006-06-04 David Turner <david@freetype.org>
* src/base/ftutil.c (ft_mem_qrealloc): Fix the function to accept

View File

@ -75,15 +75,24 @@ FT_BEGIN_HEADER
* NULL if invalid index.
*/
typedef const char*
(*PS_Glyph_NameFunc)( FT_Pointer data,
FT_UInt string_index );
(*PS_GetGlyphNameFunc)( FT_Pointer data,
FT_UInt string_index );
/*
* A function used to release the glyph name returned by
* PS_GetGlyphNameFunc, when needed
*/
typedef void
(*PS_FreeGlyphNameFunc)( FT_Pointer data,
const char* name );
typedef FT_Error
(*PS_Unicodes_InitFunc)( FT_Memory memory,
PS_Unicodes unicodes,
FT_UInt num_glyphs,
PS_Glyph_NameFunc get_glyph_name,
FT_Pointer glyph_data );
(*PS_Unicodes_InitFunc)( FT_Memory memory,
PS_Unicodes unicodes,
FT_UInt num_glyphs,
PS_GetGlyphNameFunc get_glyph_name,
PS_FreeGlyphNameFunc free_glyph_name,
FT_Pointer glyph_data );
typedef FT_UInt
(*PS_Unicodes_CharIndexFunc)( PS_Unicodes unicodes,

View File

@ -120,9 +120,10 @@
/*************************************************************************/
FT_CALLBACK_DEF( const char* )
cff_sid_to_glyph_name( CFF_Font cff,
cff_sid_to_glyph_name( TT_Face face,
FT_UInt idx )
{
CFF_Font cff = (CFF_Font) face->extra.data;
CFF_Charset charset = &cff->charset;
FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames;
FT_UInt sid = charset->sids[idx];
@ -131,6 +132,15 @@
return cff_index_get_sid_string( &cff->string_index, sid, psnames );
}
FT_CALLBACK_DEF( void )
cff_sid_free_glyph_name( TT_Face face,
const char* gname )
{
FT_Memory memory = FT_FACE_MEMORY( face );
FT_FREE( gname );
}
FT_CALLBACK_DEF( FT_Error )
cff_cmap_unicode_init( PS_Unicodes unicodes )
@ -149,7 +159,8 @@
return psnames->unicodes_init( memory,
unicodes,
cff->num_glyphs,
(PS_Glyph_NameFunc)&cff_sid_to_glyph_name,
(PS_GetGlyphNameFunc) &cff_sid_to_glyph_name,
(PS_FreeGlyphNameFunc) &cff_sid_free_glyph_name,
(FT_Pointer)cff );
}

View File

@ -276,7 +276,8 @@
return psnames->unicodes_init( memory,
unicodes,
face->type1.num_glyphs,
(PS_Glyph_NameFunc)&t1_get_glyph_name,
(PS_GetGlyphNameFunc) &t1_get_glyph_name,
(PS_FreeGlyphNameFunc) NULL,
(FT_Pointer)face );
}

View File

@ -182,11 +182,12 @@
/* Build a table that maps Unicode values to glyph indices. */
static FT_Error
ps_unicodes_init( FT_Memory memory,
PS_Unicodes table,
FT_UInt num_glyphs,
PS_Glyph_NameFunc get_glyph_name,
FT_Pointer glyph_data )
ps_unicodes_init( FT_Memory memory,
PS_Unicodes table,
FT_UInt num_glyphs,
PS_GetGlyphNameFunc get_glyph_name,
PS_FreeGlyphNameFunc free_glyph_name,
FT_Pointer glyph_data )
{
FT_Error error;
@ -220,6 +221,9 @@
map->glyph_index = n;
map++;
}
if ( free_glyph_name )
free_glyph_name( glyph_data, gname );
}
}