Commit cbb90707 authored by Kieran Kunhya's avatar Kieran Kunhya Committed by Fiona Glaser

Free user supplied data when deleting a frame

This eliminates a memory leak when calling x264_encoder_close.
parent 3d03b619
......@@ -300,6 +300,16 @@ void x264_frame_delete( x264_frame_t *frame )
x264_free( frame->mv16x16-1 );
x264_free( frame->ref[0] );
x264_free( frame->ref[1] );
if( frame->param && frame->param->param_free )
frame->param->param_free( frame->param );
if( frame->mb_info_free )
frame->mb_info_free( frame->mb_info );
if( frame->extra_sei.sei_free )
{
for( int i = 0; i < frame->extra_sei.num_payloads; i++ )
frame->extra_sei.sei_free( frame->extra_sei.payloads[i].payload );
frame->extra_sei.sei_free( frame->extra_sei.payloads );
}
x264_pthread_mutex_destroy( &frame->mutex );
x264_pthread_cond_destroy( &frame->cv );
}
......
......@@ -2878,7 +2878,10 @@ int x264_encoder_encode( x264_t *h,
{
x264_encoder_reconfig( h, h->fenc->param );
if( h->fenc->param->param_free )
{
h->fenc->param->param_free( h->fenc->param );
h->fenc->param = NULL;
}
}
// ok to call this before encoding any frames, since the initial values of fdec have b_kept_as_ref=0
......@@ -3098,12 +3101,19 @@ int x264_encoder_encode( x264_t *h,
if( x264_nal_end( h ) )
return -1;
overhead += h->out.nal[h->out.i_nal-1].i_payload + NALU_OVERHEAD - (h->param.b_annexb && h->out.i_nal-1);
if( h->fenc->extra_sei.sei_free && h->fenc->extra_sei.payloads[i].payload )
if( h->fenc->extra_sei.sei_free )
{
h->fenc->extra_sei.sei_free( h->fenc->extra_sei.payloads[i].payload );
h->fenc->extra_sei.payloads[i].payload = NULL;
}
}
if( h->fenc->extra_sei.sei_free && h->fenc->extra_sei.payloads )
if( h->fenc->extra_sei.sei_free )
{
h->fenc->extra_sei.sei_free( h->fenc->extra_sei.payloads );
h->fenc->extra_sei.payloads = NULL;
h->fenc->extra_sei.sei_free = NULL;
}
if( h->fenc->b_keyframe )
{
......@@ -3232,7 +3242,11 @@ static int x264_encoder_frame_end( x264_t *h, x264_t *thread_current,
x264_emms();
if( h->fenc->mb_info_free )
{
h->fenc->mb_info_free( h->fenc->mb_info );
h->fenc->mb_info = NULL;
h->fenc->mb_info_free = NULL;
}
/* generate buffering period sei and insert it into place */
if( h->i_thread_frames > 1 && h->fenc->b_keyframe && h->sps->vui.b_nal_hrd_parameters_present )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment