From 457b4a81a190500fbbea8bc7b5750903704e715f Mon Sep 17 00:00:00 2001 From: David Turner Date: Tue, 6 Jun 2006 08:14:14 +0000 Subject: [PATCH] * 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' --- ChangeLog | 10 ++++++++ include/freetype/internal/services/svpscmap.h | 23 +++++++++++++------ src/cff/cffcmap.c | 15 ++++++++++-- src/psaux/t1cmap.c | 3 ++- src/psnames/psmodule.c | 14 +++++++---- 5 files changed, 50 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 09b555b98..1f3a3d345 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-06-06 David Turner + + * 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 * src/base/ftutil.c (ft_mem_qrealloc): Fix the function to accept diff --git a/include/freetype/internal/services/svpscmap.h b/include/freetype/internal/services/svpscmap.h index 8f418a83a..c4e25ed63 100644 --- a/include/freetype/internal/services/svpscmap.h +++ b/include/freetype/internal/services/svpscmap.h @@ -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, diff --git a/src/cff/cffcmap.c b/src/cff/cffcmap.c index cfaaebc9f..ea703cf68 100644 --- a/src/cff/cffcmap.c +++ b/src/cff/cffcmap.c @@ -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 ); } diff --git a/src/psaux/t1cmap.c b/src/psaux/t1cmap.c index 79e58dde4..772f441f1 100644 --- a/src/psaux/t1cmap.c +++ b/src/psaux/t1cmap.c @@ -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 ); } diff --git a/src/psnames/psmodule.c b/src/psnames/psmodule.c index 631eafd0e..1a7a251db 100644 --- a/src/psnames/psmodule.c +++ b/src/psnames/psmodule.c @@ -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 ); } }