freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Git][freetype/freetype][master] [cff] Clean up memory management in the


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype][master] [cff] Clean up memory management in the old engine.
Date: Sat, 04 Mar 2023 19:13:44 +0000

Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType

Commits:

  • a2b8937d
    by Alexei Podtelezhnikov at 2023-03-04T14:00:52-05:00
    [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 changed file:

Changes:

  • src/cff/cffparse.c
    ... ... @@ -63,10 +63,7 @@
    63 63
     
    
    64 64
         /* allocate the stack buffer */
    
    65 65
         if ( FT_QNEW_ARRAY( parser->stack, stackSize ) )
    
    66
    -    {
    
    67
    -      FT_FREE( parser->stack );
    
    68 66
           goto Exit;
    
    69
    -    }
    
    70 67
     
    
    71 68
         parser->stackSize = stackSize;
    
    72 69
         parser->top       = parser->stack;    /* empty stack */
    
    ... ... @@ -82,13 +79,16 @@
    82 79
                            void*      data,
    
    83 80
                            void*      user )
    
    84 81
       {
    
    85
    -    CFF_T2_String  t2 = (CFF_T2_String)data;
    
    82
    +    FT_UNUSED( user );
    
    86 83
     
    
    84
    +    if ( data )
    
    85
    +    {
    
    86
    +      CFF_T2_String  t2 = (CFF_T2_String)data;
    
    87 87
     
    
    88
    -    FT_UNUSED( user );
    
    89 88
     
    
    90
    -    memory->free( memory, t2->start );
    
    91
    -    memory->free( memory, data );
    
    89
    +      FT_FREE( t2->start );
    
    90
    +      FT_FREE( data );
    
    91
    +    }
    
    92 92
       }
    
    93 93
     #endif /* CFF_CONFIG_OPTION_OLD_ENGINE */
    
    94 94
     
    
    ... ... @@ -1309,18 +1309,13 @@
    1309 1309
             /* Now copy the stack data in the temporary decoder object,    */
    
    1310 1310
             /* converting it back to charstring number representations     */
    
    1311 1311
             /* (this is ugly, I know).                                     */
    
    1312
    -
    
    1313
    -        node = (FT_ListNode)memory->alloc( memory,
    
    1314
    -                                           sizeof ( FT_ListNodeRec ) );
    
    1315
    -        if ( !node )
    
    1316
    -          goto Out_Of_Memory_Error;
    
    1312
    +        if ( FT_NEW( node ) )
    
    1313
    +          goto Exit;
    
    1317 1314
     
    
    1318 1315
             FT_List_Add( &parser->t2_strings, node );
    
    1319 1316
     
    
    1320
    -        t2 = (CFF_T2_String)memory->alloc( memory,
    
    1321
    -                                           sizeof ( CFF_T2_StringRec ) );
    
    1322
    -        if ( !t2 )
    
    1323
    -          goto Out_Of_Memory_Error;
    
    1317
    +        if ( FT_NEW( t2 ) )
    
    1318
    +          goto Exit;
    
    1324 1319
     
    
    1325 1320
             node->data = t2;
    
    1326 1321
     
    
    ... ... @@ -1329,9 +1324,8 @@
    1329 1324
     
    
    1330 1325
             t2_size = 5 * ( decoder.top - decoder.stack );
    
    1331 1326
     
    
    1332
    -        q = (FT_Byte*)memory->alloc( memory, t2_size );
    
    1333
    -        if ( !q )
    
    1334
    -          goto Out_Of_Memory_Error;
    
    1327
    +        if ( FT_QALLOC( q, t2_size ) )
    
    1328
    +          goto Exit;
    
    1335 1329
     
    
    1336 1330
             t2->start = q;
    
    1337 1331
             t2->limit = q + t2_size;
    
    ... ... @@ -1598,12 +1592,6 @@
    1598 1592
       Exit:
    
    1599 1593
         return error;
    
    1600 1594
     
    
    1601
    -#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
    
    1602
    -  Out_Of_Memory_Error:
    
    1603
    -    error = FT_THROW( Out_Of_Memory );
    
    1604
    -    goto Exit;
    
    1605
    -#endif
    
    1606
    -
    
    1607 1595
       Stack_Overflow:
    
    1608 1596
         error = FT_THROW( Invalid_Argument );
    
    1609 1597
         goto Exit;
    


  • reply via email to

    [Prev in Thread] Current Thread [Next in Thread]