[cff] Clean up memory management in the old engine. * src/cff/cffparse.c (finalize_t2_strings): Fix NULL-dereferencing in the out-of-memory situation, use `FT_FREE`. (cff_parser_run): Use FreeType memory allocation macros and avoid uninitialized pointers.
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 76 77 78 79 80 81 82 83 84
diff --git a/src/cff/cffparse.c b/src/cff/cffparse.c
index e16206f..eaad8d5 100644
--- a/src/cff/cffparse.c
+++ b/src/cff/cffparse.c
@@ -63,10 +63,7 @@
/* allocate the stack buffer */
if ( FT_QNEW_ARRAY( parser->stack, stackSize ) )
- {
- FT_FREE( parser->stack );
goto Exit;
- }
parser->stackSize = stackSize;
parser->top = parser->stack; /* empty stack */
@@ -82,13 +79,16 @@
void* data,
void* user )
{
- CFF_T2_String t2 = (CFF_T2_String)data;
+ FT_UNUSED( user );
+ if ( data )
+ {
+ CFF_T2_String t2 = (CFF_T2_String)data;
- FT_UNUSED( user );
- memory->free( memory, t2->start );
- memory->free( memory, data );
+ FT_FREE( t2->start );
+ FT_FREE( data );
+ }
}
#endif /* CFF_CONFIG_OPTION_OLD_ENGINE */
@@ -1309,18 +1309,13 @@
/* Now copy the stack data in the temporary decoder object, */
/* converting it back to charstring number representations */
/* (this is ugly, I know). */
-
- node = (FT_ListNode)memory->alloc( memory,
- sizeof ( FT_ListNodeRec ) );
- if ( !node )
- goto Out_Of_Memory_Error;
+ if ( FT_NEW( node ) )
+ goto Exit;
FT_List_Add( &parser->t2_strings, node );
- t2 = (CFF_T2_String)memory->alloc( memory,
- sizeof ( CFF_T2_StringRec ) );
- if ( !t2 )
- goto Out_Of_Memory_Error;
+ if ( FT_NEW( t2 ) )
+ goto Exit;
node->data = t2;
@@ -1329,9 +1324,8 @@
t2_size = 5 * ( decoder.top - decoder.stack );
- q = (FT_Byte*)memory->alloc( memory, t2_size );
- if ( !q )
- goto Out_Of_Memory_Error;
+ if ( FT_QALLOC( q, t2_size ) )
+ goto Exit;
t2->start = q;
t2->limit = q + t2_size;
@@ -1598,12 +1592,6 @@
Exit:
return error;
-#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
- Out_Of_Memory_Error:
- error = FT_THROW( Out_Of_Memory );
- goto Exit;
-#endif
-
Stack_Overflow:
error = FT_THROW( Invalid_Argument );
goto Exit;