shithub: freetype+ttf2subf

Download patch

ref: bd3849e7deefcb3c772e77f14fdbf102bead389d
parent: bcd8c0b0ebce807b5f58303fd48dc9a3e7e7605b
author: Behdad Esfahbod <[email protected]>
date: Tue Aug 27 17:43:38 EDT 2013

FT_Open_Face: Improve external stream handling.

If the font's `clazz->init_face' function wants to swap to new
stream, handling of whether original stream was external could
result to either memory leak or double free.  Mark externality into
face flags before calling `init_face' such that the clazz can handle
external streams properly.

* src/base/ftobjs.c (FT_Open_Face): Move code to set
FT_FACE_FLAG_EXTERNAL_STREAM to...
(open_face): This function.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2013-08-27  Behdad Esfahbod  <[email protected]>
+
+	FT_Open_Face: Improve external stream handling.
+
+	If the font's `clazz->init_face' function wants to swap to new
+	stream, handling of whether original stream was external could
+	result to either memory leak or double free.  Mark externality into
+	face flags before calling `init_face' such that the clazz can handle
+	external streams properly.
+
+	* src/base/ftobjs.c (FT_Open_Face): Move code to set
+	FT_FACE_FLAG_EXTERNAL_STREAM to...
+	(open_face): This function.
+
 2013-08-27  Werner Lemberg  <[email protected]>
 
 	Remove `FT_SqrtFixed' function.
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -1134,6 +1134,7 @@
   static FT_Error
   open_face( FT_Driver      driver,
              FT_Stream      stream,
+             FT_Bool        external_stream,
              FT_Long        face_index,
              FT_Int         num_params,
              FT_Parameter*  params,
@@ -1157,6 +1158,11 @@
     face->memory = memory;
     face->stream = stream;
 
+    /* set the FT_FACE_FLAG_EXTERNAL_STREAM bit for FT_Done_Face */
+    if ( external_stream )
+      face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM;
+
+
     if ( FT_NEW( internal ) )
       goto Fail;
 
@@ -2069,7 +2075,7 @@
           params     = args->params;
         }
 
-        error = open_face( driver, stream, face_index,
+        error = open_face( driver, stream, external_stream, face_index,
                            num_params, params, &face );
         if ( !error )
           goto Success;
@@ -2105,7 +2111,7 @@
             params     = args->params;
           }
 
-          error = open_face( driver, stream, face_index,
+          error = open_face( driver, stream, external_stream, face_index,
                              num_params, params, &face );
           if ( !error )
             goto Success;
@@ -2173,10 +2179,6 @@
 
   Success:
     FT_TRACE4(( "FT_Open_Face: New face object, adding to list\n" ));
-
-    /* set the FT_FACE_FLAG_EXTERNAL_STREAM bit for FT_Done_Face */
-    if ( external_stream )
-      face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM;
 
     /* add the face object to its driver's list */
     if ( FT_NEW( node ) )