* 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'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
diff --git a/ChangeLog b/ChangeLog
index 09b555b..1f3a3d3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/include/freetype/internal/services/svpscmap.h b/include/freetype/internal/services/svpscmap.h
index 8f418a8..c4e25ed 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 cfaaebc..ea703cf 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 79e58dd..772f441 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 631eafd..1a7a251 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 );
}
}