libhb: plug a few memory leaks

Noticed when debugging a memory corruption issue with valgrind


git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4122 b64f7644-9d1e-0410-96f1-a4d463321fa5
This commit is contained in:
jstebbins 2011-07-19 17:36:12 +00:00
parent 4c30ccadee
commit 244f212aa4
7 changed files with 72 additions and 16 deletions

View File

@ -57,6 +57,7 @@ hb_batch_t * hb_batch_init( char * path )
hb_list_add( d->list_file, filename ); hb_list_add( d->list_file, filename );
} }
closedir( dir );
if ( hb_list_count( d->list_file ) == 0 ) if ( hb_list_count( d->list_file ) == 0 )
{ {
hb_list_close( &d->list_file ); hb_list_close( &d->list_file );

View File

@ -1131,6 +1131,11 @@ void hb_title_close( hb_title_t ** _t )
free( t->metadata ); free( t->metadata );
} }
if ( t->video_codec_name )
{
free( t->video_codec_name );
}
free( t ); free( t );
*_t = NULL; *_t = NULL;
} }

View File

@ -624,7 +624,7 @@ struct hb_title_s
int video_codec; /* worker object id of video codec */ int video_codec; /* worker object id of video codec */
uint32_t video_stream_type; /* stream type from source stream */ uint32_t video_stream_type; /* stream type from source stream */
int video_codec_param; /* codec specific config */ int video_codec_param; /* codec specific config */
const char *video_codec_name; char *video_codec_name;
int video_bitrate; int video_bitrate;
const char *container_name; const char *container_name;
int data_rate; int data_rate;

View File

@ -68,6 +68,7 @@ static void flushDelayQueue( hb_work_private_t *pv );
static int decavcodecInit( hb_work_object_t *, hb_job_t * ); static int decavcodecInit( hb_work_object_t *, hb_job_t * );
static int decavcodecWork( hb_work_object_t *, hb_buffer_t **, hb_buffer_t ** ); static int decavcodecWork( hb_work_object_t *, hb_buffer_t **, hb_buffer_t ** );
static void decavcodecClose( hb_work_object_t * ); static void decavcodecClose( hb_work_object_t * );
static void decavcodeciClose( hb_work_object_t * );
static int decavcodecInfo( hb_work_object_t *, hb_work_info_t * ); static int decavcodecInfo( hb_work_object_t *, hb_work_info_t * );
static int decavcodecBSInfo( hb_work_object_t *, const hb_buffer_t *, hb_work_info_t * ); static int decavcodecBSInfo( hb_work_object_t *, const hb_buffer_t *, hb_work_info_t * );
@ -246,7 +247,7 @@ static int decavcodecInit( hb_work_object_t * w, hb_job_t * job )
*********************************************************************** ***********************************************************************
* *
**********************************************************************/ **********************************************************************/
static void closePrivData( hb_work_private_t ** ppv ) static void closePrivData( hb_work_private_t ** ppv, int free_av_context )
{ {
hb_work_private_t * pv = *ppv; hb_work_private_t * pv = *ppv;
@ -272,6 +273,10 @@ static void closePrivData( hb_work_private_t ** ppv )
{ {
hb_avcodec_close( pv->context ); hb_avcodec_close( pv->context );
} }
if ( free_av_context )
{
av_free( pv->context );
}
if ( pv->list ) if ( pv->list )
{ {
hb_list_empty( &pv->list ); hb_list_empty( &pv->list );
@ -302,10 +307,30 @@ static void decavcodecClose( hb_work_object_t * w )
while ( ( ff_pv = hb_list_item( pv->list, 0 ) ) != NULL ) while ( ( ff_pv = hb_list_item( pv->list, 0 ) ) != NULL )
{ {
hb_list_rem( pv->ff_audio_list, ff_pv ); hb_list_rem( pv->ff_audio_list, ff_pv );
closePrivData( &ff_pv ); closePrivData( &ff_pv, 0 );
} }
} }
closePrivData( &pv ); closePrivData( &pv, 1 );
w->private_data = NULL;
}
}
static void decavcodeciClose( hb_work_object_t * w )
{
hb_work_private_t * pv = w->private_data;
if ( pv )
{
if ( pv->ff_audio_list != NULL )
{
hb_work_private_t * ff_pv;
while ( ( ff_pv = hb_list_item( pv->list, 0 ) ) != NULL )
{
hb_list_rem( pv->ff_audio_list, ff_pv );
closePrivData( &ff_pv, 0 );
}
}
closePrivData( &pv, 0 );
w->private_data = NULL; w->private_data = NULL;
} }
} }
@ -560,6 +585,7 @@ static int decavcodecBSInfo( hb_work_object_t *w, const hb_buffer_t *buf,
if ( parser != NULL ) if ( parser != NULL )
av_parser_close( parser ); av_parser_close( parser );
hb_avcodec_close( context ); hb_avcodec_close( context );
av_free( context );
return ret; return ret;
} }
@ -1662,7 +1688,7 @@ hb_work_object_t hb_decavcodecvi =
"Video decoder (ffmpeg streams)", "Video decoder (ffmpeg streams)",
decavcodecviInit, decavcodecviInit,
decavcodecviWork, decavcodecviWork,
decavcodecClose, decavcodeciClose,
decavcodecviInfo, decavcodecviInfo,
decavcodecvBSInfo decavcodecvBSInfo
}; };
@ -1673,7 +1699,7 @@ hb_work_object_t hb_decavcodecai =
"Audio decoder (ffmpeg streams)", "Audio decoder (ffmpeg streams)",
decavcodecviInit, decavcodecviInit,
decavcodecaiWork, decavcodecaiWork,
decavcodecClose, decavcodeciClose,
decavcodecInfo, decavcodecInfo,
decavcodecBSInfo decavcodecBSInfo
}; };

View File

@ -302,6 +302,7 @@ static int decdcaBSInfo( hb_work_object_t *w, const hb_buffer_t *b,
if ( i >= b->size - 7 ) if ( i >= b->size - 7 )
{ {
/* didn't find DCA sync */ /* didn't find DCA sync */
dca_free( state );
return 0; return 0;
} }
@ -362,5 +363,6 @@ static int decdcaBSInfo( hb_work_object_t *w, const hb_buffer_t *b,
info->channel_map = &hb_qt_chan_map; info->channel_map = &hb_qt_chan_map;
dca_free( state );
return 1; return 1;
} }

View File

@ -1402,6 +1402,7 @@ void hb_add( hb_handle_t * h, hb_job_t * job )
hb_list_add( title_copy->list_attachment, hb_attachment_copy(attachment) ); hb_list_add( title_copy->list_attachment, hb_attachment_copy(attachment) );
} }
} }
title_copy->video_codec_name = strdup( title->video_codec_name );
/* /*
* The following code is confusing, there are two ways in which * The following code is confusing, there are two ways in which
@ -1747,6 +1748,8 @@ void hb_close( hb_handle_t ** _h )
hb_lock_close( &h->state_lock ); hb_lock_close( &h->state_lock );
hb_lock_close( &h->pause_lock ); hb_lock_close( &h->pause_lock );
free( h->interjob );
free( h ); free( h );
*_h = NULL; *_h = NULL;
} }

View File

@ -188,6 +188,16 @@ static void ScanFunc( void * _data )
{ {
/* TODO: free things */ /* TODO: free things */
hb_list_rem( data->list_title, title ); hb_list_rem( data->list_title, title );
for( j = 0; j < hb_list_count( title->list_audio ); j++)
{
audio = hb_list_item( title->list_audio, j );
if ( audio->priv.scan_cache )
{
hb_fifo_flush( audio->priv.scan_cache );
hb_fifo_close( &audio->priv.scan_cache );
}
}
hb_title_close( &title );
continue; continue;
} }
@ -195,6 +205,11 @@ static void ScanFunc( void * _data )
for( j = 0; j < hb_list_count( title->list_audio ); ) for( j = 0; j < hb_list_count( title->list_audio ); )
{ {
audio = hb_list_item( title->list_audio, j ); audio = hb_list_item( title->list_audio, j );
if ( audio->priv.scan_cache )
{
hb_fifo_flush( audio->priv.scan_cache );
hb_fifo_close( &audio->priv.scan_cache );
}
if( !audio->config.in.bitrate ) if( !audio->config.in.bitrate )
{ {
hb_log( "scan: removing audio 0x%x because no bitrate found", hb_log( "scan: removing audio 0x%x because no bitrate found",
@ -203,11 +218,6 @@ static void ScanFunc( void * _data )
free( audio ); free( audio );
continue; continue;
} }
if ( audio->priv.scan_cache )
{
hb_fifo_flush( audio->priv.scan_cache );
hb_fifo_close( &audio->priv.scan_cache );
}
j++; j++;
} }
@ -449,7 +459,6 @@ static void most_common_info( info_list_t *info_list, hb_work_info_t *info )
biggest = i; biggest = i;
} }
*info = info_list[biggest].info; *info = info_list[biggest].info;
free( info_list );
} }
/*********************************************************************** /***********************************************************************
@ -497,6 +506,8 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title )
if ( *data->die ) if ( *data->die )
{ {
free( info_list );
free( crops );
return 0; return 0;
} }
if (data->bd) if (data->bd)
@ -639,6 +650,8 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title )
if( ! vid_buf ) if( ! vid_buf )
{ {
hb_log( "scan: could not get a decoded picture" ); hb_log( "scan: could not get a decoded picture" );
vid_decoder->close( vid_decoder );
free( vid_decoder );
continue; continue;
} }
@ -659,12 +672,13 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title )
free( vid_decoder ); free( vid_decoder );
continue; continue;
} }
vid_decoder->close( vid_decoder );
free( vid_decoder );
remember_info( info_list, &vid_info ); remember_info( info_list, &vid_info );
if ( title->video_codec_name == NULL )
{
title->video_codec_name = strdup( vid_info.name ); title->video_codec_name = strdup( vid_info.name );
}
title->width = vid_info.width; title->width = vid_info.width;
title->height = vid_info.height; title->height = vid_info.height;
title->rate = vid_info.rate; title->rate = vid_info.rate;
@ -813,6 +827,9 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title )
++npreviews; ++npreviews;
skip_preview: skip_preview:
vid_decoder->close( vid_decoder );
free( vid_decoder );
/* Make sure we found audio rates and bitrates */ /* Make sure we found audio rates and bitrates */
for( j = 0; j < hb_list_count( title->list_audio ); j++ ) for( j = 0; j < hb_list_count( title->list_audio ); j++ )
{ {
@ -886,7 +903,6 @@ skip_preview:
title->crop[2] = EVEN( crops->l[i] ); title->crop[2] = EVEN( crops->l[i] );
title->crop[3] = EVEN( crops->r[i] ); title->crop[3] = EVEN( crops->r[i] );
} }
free( crops );
hb_log( "scan: %d previews, %dx%d, %.3f fps, autocrop = %d/%d/%d/%d, " hb_log( "scan: %d previews, %dx%d, %.3f fps, autocrop = %d/%d/%d/%d, "
"aspect %s, PAR %d:%d", "aspect %s, PAR %d:%d",
@ -907,6 +923,8 @@ skip_preview:
title->detected_interlacing = 0; title->detected_interlacing = 0;
} }
} }
free( crops );
free( info_list );
while( ( buf_es = hb_list_item( list_es, 0 ) ) ) while( ( buf_es = hb_list_item( list_es, 0 ) ) )
{ {
@ -996,6 +1014,7 @@ static void LookForAudio( hb_title_t * title, hb_buffer_t * b )
if ( !info.bitrate ) if ( !info.bitrate )
{ {
/* didn't find any info */ /* didn't find any info */
free( w );
return; return;
} }
hb_fifo_flush( audio->priv.scan_cache ); hb_fifo_flush( audio->priv.scan_cache );