ref: 457b4a81a190500fbbea8bc7b5750903704e715f
parent: d724f20e056ad28e2197fa4e690703de78e15441
author: David Turner <[email protected]>
date: Tue Jun 6 04:14:14 EDT 2006
* 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'
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2006-06-06 David Turner <[email protected]>
+
+ * 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 <[email protected]>
* src/base/ftutil.c (ft_mem_qrealloc): Fix the function to accept
--- a/include/freetype/internal/services/svpscmap.h
+++ b/include/freetype/internal/services/svpscmap.h
@@ -75,15 +75,24 @@
* 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,
--- 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,7 +132,16 @@
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 );
}
--- 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 );
}
--- 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 );
}
}