Index: encoder/analyse.h =================================================================== --- encoder/analyse.h (revision 187) +++ encoder/analyse.h (working copy) @@ -27,4 +27,5 @@ void x264_macroblock_analyse( x264_t *h ); void x264_slicetype_decide( x264_t *h ); +void x264_macroblock_cleanup(void); #endif Index: encoder/encoder.c =================================================================== --- encoder/encoder.c (revision 187) +++ encoder/encoder.c (working copy) @@ -1568,5 +1568,6 @@ x264_macroblock_cache_end( h ); x264_free( h->out.p_bitstream ); x264_free( h ); + x264_macroblock_cleanup(); } Index: encoder/analyse.c =================================================================== --- encoder/analyse.c (revision 187) +++ encoder/analyse.c (working copy) @@ -139,17 +139,29 @@ 5, 3, 3, 1 }; +static int16_t *p_cost_mv[52]; +static int16_t *p_cost_mv_initial[52]; +void x264_macroblock_cleanup (void) +{ + unsigned int ix; + for (ix = 0; ix < sizeof(p_cost_mv) / sizeof(*p_cost_mv); ix++) { + if (p_cost_mv_initial[ix] != NULL) { + free(p_cost_mv_initial[ix]); + p_cost_mv_initial[ix] = NULL; + p_cost_mv[ix] = NULL; + } + } +} /* initialize an array of lambda*nbits for all possible mvs */ static void x264_mb_analyse_load_costs( x264_t *h, x264_mb_analysis_t *a ) { - static int16_t *p_cost_mv[52]; if( !p_cost_mv[a->i_qp] ) { /* could be faster, but isn't called many times */ /* factor of 4 from qpel, 2 from sign, and 2 because mv can be opposite from mvp */ int i; - p_cost_mv[a->i_qp] = x264_malloc( (4*4*h->param.analyse.i_mv_range + 1) * sizeof(int16_t) ); + p_cost_mv_initial[a->i_qp] = p_cost_mv[a->i_qp] = x264_malloc( (4*4*h->param.analyse.i_mv_range + 1) * sizeof(int16_t) ); p_cost_mv[a->i_qp] += 2*4*h->param.analyse.i_mv_range; for( i = 0; i <= 2*4*h->param.analyse.i_mv_range; i++ ) {