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.
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
diff --git a/ChangeLog b/ChangeLog
index 5647367..399db54 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2013-08-27 Behdad Esfahbod <behdad@google.com>
+
+ 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 <wl@gnu.org>
Remove `FT_SqrtFixed' function.
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index 157bf45..4218f3f 100644
--- 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;
@@ -2174,10 +2180,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 ) )
goto Fail;