Commit c9669a8a632b21cdb772456f5515692df353da58

suzuki toshiya 2010-01-30T02:24:25

[sfnt] Fix memory leaks in previous patch.

diff --git a/ChangeLog b/ChangeLog
index 1ff5af6..c2dea8f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2010-01-29  suzuki toshiya  <mpsuzuki@hiroshima-u.ac.jp>
 
+	Fix memory leaks in previous patch.
+
+	* src/sfnt/sfobjs.c (sfnt_load_face): Don't overwrite the strings
+	allocated for face->root.family_name and style_name.
+
+2010-01-29  suzuki toshiya  <mpsuzuki@hiroshima-u.ac.jp>
+
 	New parameters for FT_Open_Face() to ignore preferred family names.
 
 	Preferred family names should be used for legacy systems that
diff --git a/src/sfnt/sfobjs.c b/src/sfnt/sfobjs.c
index f83e1ba..b74b1a9 100644
--- a/src/sfnt/sfobjs.c
+++ b/src/sfnt/sfobjs.c
@@ -737,29 +737,33 @@
     /* Foundation (WPF).  This flag has been introduced in version   */
     /* 1.5 of the OpenType specification (May 2008).                 */
 
+    face->root.family_name = NULL;
+    face->root.style_name  = NULL;
     if ( face->os2.version != 0xFFFFU && face->os2.fsSelection & 256 )
     {
-      GET_NAME( FONT_FAMILY, &face->root.family_name );
-      if ( !face->root.family_name || !ignore_preferred_family )
+      if ( !ignore_preferred_family )
         GET_NAME( PREFERRED_FAMILY, &face->root.family_name );
+      if ( !face->root.family_name )
+        GET_NAME( FONT_FAMILY, &face->root.family_name );
 
-      GET_NAME( FONT_SUBFAMILY, &face->root.style_name );
-      if ( !face->root.style_name || !ignore_preferred_subfamily )
+      if ( !ignore_preferred_subfamily )
         GET_NAME( PREFERRED_SUBFAMILY, &face->root.style_name );
+      if ( !face->root.style_name )
+        GET_NAME( FONT_SUBFAMILY, &face->root.style_name );
     }
     else
     {
       GET_NAME( WWS_FAMILY, &face->root.family_name );
+      if ( !face->root.family_name && !ignore_preferred_family )
+        GET_NAME( PREFERRED_FAMILY, &face->root.family_name );
       if ( !face->root.family_name )
         GET_NAME( FONT_FAMILY, &face->root.family_name );
-      if ( !face->root.family_name || !ignore_preferred_family )
-        GET_NAME( PREFERRED_FAMILY, &face->root.family_name );
 
       GET_NAME( WWS_SUBFAMILY, &face->root.style_name );
+      if ( !face->root.style_name && !ignore_preferred_subfamily )
+        GET_NAME( PREFERRED_SUBFAMILY, &face->root.style_name );
       if ( !face->root.style_name )
         GET_NAME( FONT_SUBFAMILY, &face->root.style_name );
-      if ( !face->root.style_name || !ignore_preferred_subfamily )
-        GET_NAME( PREFERRED_SUBFAMILY, &face->root.style_name );
     }
 
     /* now set up root fields */