Show
Ignore:
Timestamp:
20/08/08 23:22:22 (3 months ago)
Author:
Rémi Duraffort <ivoire@videolan.org>
git-committer:
Rémi Duraffort <ivoire@videolan.org> 1219267342 +0200
git-parent:

[131a15b62ba4440b80df480f9c56448a47785800]

git-author:
Rémi Duraffort <ivoire@videolan.org> 1219261335 +0200
Message:

Fix potential memleaks (free the module if it can't be loaded)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/audio_filter/scaletempo.c

    reaa8fb6 r2c28bcb  
    289289    /* overlap */ 
    290290    unsigned frames_overlap = frames_stride * p->percent_overlap; 
    291     if( frames_overlap < 1 ) { /* if no overlap */ 
     291    if( frames_overlap < 1 ) 
     292    { /* if no overlap */ 
    292293        p->bytes_overlap    = 0; 
    293294        p->bytes_standing   = p->bytes_stride; 
    294295        p->samples_standing = p->bytes_standing / p->bytes_per_sample; 
    295296        p->output_overlap   = NULL; 
    296     } else { 
     297    } 
     298    else 
     299    { 
    297300        unsigned prev_overlap   = p->bytes_overlap; 
    298301        p->bytes_overlap    = frames_overlap * p->bytes_per_frame; 
     
    302305        p->buf_overlap      = malloc( p->bytes_overlap ); 
    303306        p->table_blend      = malloc( p->samples_overlap * 4 ); /* sizeof (int32|float) */ 
    304         if( ! p->buf_overlap || ! p->table_blend ) { 
     307        if( !p->buf_overlap || !p->table_blend ) 
    305308            return VLC_ENOMEM; 
    306         } 
    307         if( p->bytes_overlap > prev_overlap ) { 
     309        if( p->bytes_overlap > prev_overlap ) 
    308310            memset( (uint8_t *)p->buf_overlap + prev_overlap, 0, p->bytes_overlap - prev_overlap ); 
    309         } 
     311 
    310312        float *pb = p->table_blend; 
    311313        float t = (float)frames_overlap; 
    312         for( i = 0; i<frames_overlap; i++ ) { 
     314        for( i = 0; i<frames_overlap; i++ ) 
     315        { 
    313316            float v = i / t; 
    314             for( j = 0; j < p->samples_per_frame; j++ ) { 
     317            for( j = 0; j < p->samples_per_frame; j++ ) 
    315318                *pb++ = v; 
    316             } 
    317319        } 
    318320        p->output_overlap = output_overlap_float; 
     
    321323    /* best overlap */ 
    322324    p->frames_search = ( frames_overlap <= 1 ) ? 0 : p->ms_search * p->sample_rate / 1000.0; 
    323     if( p->frames_search < 1 ) { /* if no search */ 
     325    if( p->frames_search < 1 ) 
     326    { /* if no search */ 
    324327        p->best_overlap_offset = NULL; 
    325     } else { 
     328    } 
     329    else 
     330    { 
    326331        unsigned bytes_pre_corr = ( p->samples_overlap - p->samples_per_frame ) * 4; /* sizeof (int32|float) */ 
    327332        p->buf_pre_corr = malloc( bytes_pre_corr ); 
    328333        p->table_window = malloc( bytes_pre_corr ); 
    329         if( ! p->buf_pre_corr || ! p->table_window ) { 
     334        if( ! p->buf_pre_corr || ! p->table_window ) 
    330335            return VLC_ENOMEM; 
    331         } 
    332336        float *pw = p->table_window; 
    333         for( i = 1; i<frames_overlap; i++ ) { 
     337        for( i = 1; i<frames_overlap; i++ ) 
     338        { 
    334339            float v = i * ( frames_overlap - i ); 
    335             for( j = 0; j < p->samples_per_frame; j++ ) { 
     340            for( j = 0; j < p->samples_per_frame; j++ ) 
    336341                *pw++ = v; 
    337             } 
    338342        } 
    339343        p->best_overlap_offset = best_overlap_offset_float; 
     
    341345 
    342346    unsigned new_size = ( p->frames_search + frames_stride + frames_overlap ) * p->bytes_per_frame; 
    343     if( p->bytes_queued > new_size ) { 
    344         if( p->bytes_to_slide > p->bytes_queued ) { 
     347    if( p->bytes_queued > new_size ) 
     348    { 
     349        if( p->bytes_to_slide > p->bytes_queued ) 
     350        { 
    345351          p->bytes_to_slide -= p->bytes_queued; 
    346352          p->bytes_queued    = 0; 
    347         } else { 
     353        } 
     354        else 
     355        { 
    348356            unsigned new_queued = __MIN( p->bytes_queued - p->bytes_to_slide, new_size ); 
    349357            memmove( p->buf_queue, 
     
    356364    p->bytes_queue_max = new_size; 
    357365    p->buf_queue = malloc( p->bytes_queue_max ); 
    358     if( ! p->buf_queue ) { 
     366    if( ! p->buf_queue ) 
    359367        return VLC_ENOMEM; 
    360     } 
    361368 
    362369    p->bytes_stride_scaled  = p->bytes_stride * p->scale; 
     
    401408 
    402409    if( ! b_fit ) 
    403     { 
    404410        return VLC_EGENERIC; 
    405     } 
    406411 
    407412    p_filter->pf_do_work = DoWork; 
     
    411416    p_sys = p_filter->p_sys = malloc( sizeof(aout_filter_sys_t) ); 
    412417    if( ! p_sys ) 
    413     { 
    414418        return VLC_ENOMEM; 
    415     } 
    416419 
    417420    p_sys->scale             = 1.0; 
     
    447450    p_sys->bytes_to_slide = 0; 
    448451    p_sys->frames_stride_error = 0; 
    449     return reinit_buffers( p_filter ); 
     452 
     453    if( reinit_buffers( p_filter ) != VLC_SUCCESS ) 
     454    { 
     455        Close( p_this ); 
     456        return VLC_EGENERIC; 
     457    } 
     458    return VLC_SUCCESS; 
    450459} 
    451460