freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype][gsoc-craig-2023] Fix memory leak in error handl


From: Craig White (@gerzytet)
Subject: [Git][freetype/freetype][gsoc-craig-2023] Fix memory leak in error handling logic
Date: Wed, 27 Sep 2023 03:00:48 +0000

Craig White pushed to branch gsoc-craig-2023 at FreeType / FreeType

Commits:

  • 2e5620a4
    by Craig White at 2023-09-26T23:00:10-04:00
    Fix memory leak in error handling logic
    

1 changed file:

Changes:

  • src/autofit/afadjust.c
    ... ... @@ -21,7 +21,7 @@
    21 21
     FT_LOCAL_ARRAY_DEF( AF_AdjustmentDatabaseEntry )
    
    22 22
     adjustment_database[] =
    
    23 23
     {
    
    24
    -    {0x21,  AF_VERTICAL_ADJUSTMENT_TOP_CONTOUR_UP}, /* !
    
    24
    +    {0x21,  AF_VERTICAL_ADJUSTMENT_TOP_CONTOUR_UP}, /* ! */
    
    25 25
         {0x69,  AF_VERTICAL_ADJUSTMENT_TOP_CONTOUR_UP}, /* i */
    
    26 26
         {0x6A,  AF_VERTICAL_ADJUSTMENT_TOP_CONTOUR_UP}, /* j */
    
    27 27
         {0xA1,  AF_VERTICAL_ADJUSTMENT_TOP_CONTOUR_UP}, /*Inverted Exclamation Mark*/
    
    ... ... @@ -298,14 +298,19 @@ af_all_glyph_variants_helper( hb_font_t *font,
    298 298
                                   FT_UInt32 num_features,
    
    299 299
                                   hb_set_t* result )
    
    300 300
     {
    
    301
    +    FT_Error error;
    
    301 302
         /*get the list of glyphs that are created by only transforming based on the
    
    302 303
         features in current features*/
    
    303
    -    hb_set_t *baseline_glyphs = hb_set_create();
    
    304
    +    hb_set_t *baseline_glyphs = NULL, *new_glyphs = NULL;
    
    305
    +    baseline_glyphs = hb_set_create();
    
    304 306
         if ( !hb_set_allocation_successful( baseline_glyphs ) )
    
    305 307
         {
    
    306
    -        return FT_Err_Out_Of_Memory;
    
    308
    +        error = FT_Err_Out_Of_Memory;
    
    309
    +        goto Exit;
    
    307 310
         }
    
    308 311
     
    
    312
    +
    
    313
    +
    
    309 314
         hb_ot_shape_glyphs_closure ( font,
    
    310 315
                                      buffer,
    
    311 316
                                      current_features,
    
    ... ... @@ -313,7 +318,8 @@ af_all_glyph_variants_helper( hb_font_t *font,
    313 318
                                      baseline_glyphs );
    
    314 319
         if ( !hb_set_allocation_successful( baseline_glyphs ) )
    
    315 320
         {
    
    316
    -        return FT_Err_Out_Of_Memory;
    
    321
    +        error = FT_Err_Out_Of_Memory;
    
    322
    +        goto Exit;
    
    317 323
         }
    
    318 324
     
    
    319 325
         /*Add these baseline glyphs to the results.  The baseline glyphs
    
    ... ... @@ -321,11 +327,13 @@ af_all_glyph_variants_helper( hb_font_t *font,
    321 327
         hb_set_union( result, baseline_glyphs );
    
    322 328
         if ( !hb_set_allocation_successful( result ) )
    
    323 329
         {
    
    324
    -        return FT_Err_Out_Of_Memory;
    
    330
    +        error = FT_Err_Out_Of_Memory;
    
    331
    +        goto Exit;
    
    325 332
         }
    
    326 333
         if ( hb_set_get_population( feature_tag_pool ) == 0 )
    
    327 334
         {
    
    328
    -        return FT_Err_Ok;
    
    335
    +        error = FT_Err_Out_Of_Memory;
    
    336
    +        goto Exit;
    
    329 337
         }
    
    330 338
     
    
    331 339
         /*setup to try adding different features to current_features
    
    ... ... @@ -338,10 +346,11 @@ af_all_glyph_variants_helper( hb_font_t *font,
    338 346
         0 disables the feature, non-zero (usually 1) enables the feature. For features implemented as lookup type 3 (like 'salt') the value is a one based index into the alternates.
    
    339 347
         this algorithm does not handle these lookup type 3 cases fully*/
    
    340 348
     
    
    341
    -    hb_set_t *new_glyphs = hb_set_create();
    
    349
    +    new_glyphs = hb_set_create();
    
    342 350
         if ( !hb_set_allocation_successful( new_glyphs ) )
    
    343 351
         {
    
    344
    -        return FT_Err_Out_Of_Memory;
    
    352
    +        error = FT_Err_Out_Of_Memory;
    
    353
    +        goto Exit;
    
    345 354
         }
    
    346 355
     
    
    347 356
         hb_tag_t feature_tag = HB_SET_VALUE_INVALID;
    
    ... ... @@ -356,7 +365,8 @@ af_all_glyph_variants_helper( hb_font_t *font,
    356 365
                                          new_glyphs );
    
    357 366
             if ( !hb_set_allocation_successful( new_glyphs ) )
    
    358 367
             {
    
    359
    -            return FT_Err_Out_Of_Memory;
    
    368
    +            error = FT_Err_Out_Of_Memory;
    
    369
    +            goto Exit;
    
    360 370
             }
    
    361 371
     
    
    362 372
             hb_set_subtract( new_glyphs, result );
    
    ... ... @@ -370,16 +380,17 @@ af_all_glyph_variants_helper( hb_font_t *font,
    370 380
                 /*remove this feature from the feature pool so that
    
    371 381
                 the later recursion won't try it*/
    
    372 382
                 hb_set_del( feature_tag_pool, feature_tag );
    
    373
    -            FT_Error error = af_all_glyph_variants_helper( font,
    
    374
    -                                                           buffer,
    
    375
    -                                                           feature_tag_pool,
    
    376
    -                                                           current_features,
    
    377
    -                                                           num_features + 1,
    
    378
    -                                                           result );
    
    383
    +            error = af_all_glyph_variants_helper( font,
    
    384
    +                                                  buffer,
    
    385
    +                                                  feature_tag_pool,
    
    386
    +                                                  current_features,
    
    387
    +                                                  num_features + 1,
    
    388
    +                                                  result );
    
    379 389
                 if ( error )
    
    380 390
                 {
    
    381
    -                return error;
    
    391
    +                goto Exit;
    
    382 392
                 }
    
    393
    +
    
    383 394
                 /*add back the feature we removed*/
    
    384 395
                 hb_set_add( feature_tag_pool, feature_tag );
    
    385 396
                 if ( !hb_set_allocation_successful( feature_tag_pool ) ) {
    
    ... ... @@ -388,7 +399,7 @@ af_all_glyph_variants_helper( hb_font_t *font,
    388 399
             } /* if( !hb_set_is_subset( glyphs, result ) ) */
    
    389 400
     
    
    390 401
         } /*while ( hb_set_next( feature_tag_pool, &feature_tag ) )*/
    
    391
    -
    
    402
    +Exit:
    
    392 403
         hb_set_destroy( baseline_glyphs );
    
    393 404
         hb_set_destroy( new_glyphs );
    
    394 405
         return FT_Err_Ok;
    


  • reply via email to

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