[x264-devel] libx264 memory leak

Jason Garrett-Glaser darkshikari at gmail.com
Tue Mar 3 11:19:56 CET 2009


2009/3/3 191919 <191919 at gmail.com>:
> I found a memory leak in x264_mb_analyse_load_costs. It keeps some
> x264_malloc'ed pointer to a global array, but no one remembers to free them
> in x264_encoder_close.
>
>  184     if( !p_cost_mv[a->i_qp] )
>  185     {
>  186         x264_emms();
>  187         /* could be faster, but isn't called many times */
>  188         /* factor of 4 from qpel, 2 from sign, and 2 because mv can be
> opposite from mvp */
>  189         p_cost_mv[a->i_qp] = x264_malloc( (4*4*2048 + 1) *
> sizeof(int16_t) );
>  190         p_cost_mv[a->i_qp] += 2*4*2048;
>  191         for( i = 0; i <= 2*4*2048; i++ )
>
> and
>
>  207         for( j=0; j<4; j++ )
>  208         {
>  209             x264_cost_mv_fpel[a->i_qp][j] = x264_malloc( (4*2048 + 1) *
> sizeof(int16_t) );
>  210             x264_cost_mv_fpel[a->i_qp][j] += 2*2048;
>  211             for( i = -2*2048; i < 2*2048; i++ )
>  212                 x264_cost_mv_fpel[a->i_qp][j][i] =
> p_cost_mv[a->i_qp][i*4+j];
>  213         }
>
> valgrind reported:
>
> ==54848== 917,532 bytes in 14 blocks are possibly lost in loss record 10 of
> 10
> ==54848==    at 0xA61D63: malloc (vg_replace_malloc.c:192)
> ==54848==    by 0x403B24: x264_mb_analyse_load_costs (in
> /usr/local/bin/ffmpeg)
> ==54848==    by 0x3FF87D2D: ???
>
> Regards,
> jh
>
> _______________________________________________
> x264-devel mailing list
> x264-devel at videolan.org
> http://mailman.videolan.org/listinfo/x264-devel
>
>

This is intentional.  Because the arrays are static, if libx264 is
called multiple times from the same application, it will not need to
allocate them separately for each process, thus saving memory.

Dark Shikari


More information about the x264-devel mailing list