From bd3849e7deefcb3c772e77f14fdbf102bead389d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 27 Aug 2013 21:43:38 +0200 Subject: [PATCH] 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. --- ChangeLog | 14 ++++++++++++++ src/base/ftobjs.c | 14 ++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 564736734..399db545f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2013-08-27 Behdad Esfahbod + + 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 Remove `FT_SqrtFixed' function. diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index 157bf4563..4218f3fa0 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;