>From 9df5473a55db096db82a984cd2cf2159e9fe03ef Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod
Date: Sun, 18 Aug 2013 23:43:35 -0400 Subject: [PATCH 1/3] FT_Open_Face: improve external stream handling If the font clazz->init_face 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 the init_face such that the clazz can handle external streams properly. --- src/base/ftobjs.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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; -- 1.8.3