@@ -178,10 +178,18 @@ void Read_name(struct TTFONT *font)
178
178
179
179
table_ptr = NULL ;
180
180
181
- /* Set default values to avoid future references to */
182
- /* undefined pointers. */
183
- font->PostName = font->FullName =
184
- font->FamilyName = font->Version = font->Style = (char *)" unknown" ;
181
+ /* Set default values to avoid future references to undefined
182
+ * pointers. Allocate each of PostName, FullName, FamilyName,
183
+ * Version, and Style separately so they can be freed safely. */
184
+ for (char **ptr = &(font->PostName ); ptr != NULL ; ) {
185
+ *ptr = (char *) calloc (sizeof (char ), strlen (" unknown" )+1 );
186
+ strcpy (*ptr, " unknown" );
187
+ if (ptr == &(font->PostName )) ptr = &(font->FullName );
188
+ else if (ptr == &(font->FullName )) ptr = &(font->FamilyName );
189
+ else if (ptr == &(font->FamilyName )) ptr = &(font->Version );
190
+ else if (ptr == &(font->Version )) ptr = &(font->Style );
191
+ else ptr = NULL ;
192
+ }
185
193
font->Copyright = font->Trademark = (char *)NULL ;
186
194
187
195
table_ptr = GetTable (font, " name" ); /* pointer to table */
@@ -222,6 +230,7 @@ void Read_name(struct TTFONT *font)
222
230
/* Font Family name */
223
231
if ( platform == 1 && nameid == 1 )
224
232
{
233
+ free (font->FamilyName );
225
234
font->FamilyName = (char *)calloc (sizeof (char ),length+1 );
226
235
strncpy (font->FamilyName ,(const char *)strings+offset,length);
227
236
font->FamilyName [length]=(char )NULL ;
@@ -237,6 +246,7 @@ void Read_name(struct TTFONT *font)
237
246
/* Font Family name */
238
247
if ( platform == 1 && nameid == 2 )
239
248
{
249
+ free (font->Style );
240
250
font->Style = (char *)calloc (sizeof (char ),length+1 );
241
251
strncpy (font->Style ,(const char *)strings+offset,length);
242
252
font->Style [length]=(char )NULL ;
@@ -252,6 +262,7 @@ void Read_name(struct TTFONT *font)
252
262
/* Full Font name */
253
263
if ( platform == 1 && nameid == 4 )
254
264
{
265
+ free (font->FullName );
255
266
font->FullName = (char *)calloc (sizeof (char ),length+1 );
256
267
strncpy (font->FullName ,(const char *)strings+offset,length);
257
268
font->FullName [length]=(char )NULL ;
@@ -267,6 +278,7 @@ void Read_name(struct TTFONT *font)
267
278
/* Version string */
268
279
if ( platform == 1 && nameid == 5 )
269
280
{
281
+ free (font->Version );
270
282
font->Version = (char *)calloc (sizeof (char ),length+1 );
271
283
strncpy (font->Version ,(const char *)strings+offset,length);
272
284
font->Version [length]=(char )NULL ;
@@ -282,6 +294,7 @@ void Read_name(struct TTFONT *font)
282
294
/* PostScript name */
283
295
if ( platform == 1 && nameid == 6 )
284
296
{
297
+ free (font->PostName );
285
298
font->PostName = (char *)calloc (sizeof (char ),length+1 );
286
299
strncpy (font->PostName ,(const char *)strings+offset,length);
287
300
font->PostName [length]=(char )NULL ;
0 commit comments