diff options
author | jstebbins <[email protected]> | 2011-07-19 17:36:12 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2011-07-19 17:36:12 +0000 |
commit | 244f212aa465806e34e9c4640afffbe2dccefc4a (patch) | |
tree | c88b83dabd6f233f87907f45678314c66f195b7f /libhb | |
parent | 4c30ccadee5199d8c9bd0a4c4d38b50216cac409 (diff) |
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
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/batch.c | 1 | ||||
-rw-r--r-- | libhb/common.c | 5 | ||||
-rw-r--r-- | libhb/common.h | 2 | ||||
-rw-r--r-- | libhb/decavcodec.c | 36 | ||||
-rw-r--r-- | libhb/decdca.c | 2 | ||||
-rw-r--r-- | libhb/hb.c | 3 | ||||
-rw-r--r-- | libhb/scan.c | 39 |
7 files changed, 72 insertions, 16 deletions
diff --git a/libhb/batch.c b/libhb/batch.c index 698798c7b..e96520a67 100644 --- a/libhb/batch.c +++ b/libhb/batch.c @@ -57,6 +57,7 @@ hb_batch_t * hb_batch_init( char * path ) hb_list_add( d->list_file, filename ); } + closedir( dir ); if ( hb_list_count( d->list_file ) == 0 ) { hb_list_close( &d->list_file ); diff --git a/libhb/common.c b/libhb/common.c index 4acc293e2..3497a24f4 100644 --- a/libhb/common.c +++ b/libhb/common.c @@ -1131,6 +1131,11 @@ void hb_title_close( hb_title_t ** _t ) free( t->metadata ); } + if ( t->video_codec_name ) + { + free( t->video_codec_name ); + } + free( t ); *_t = NULL; } diff --git a/libhb/common.h b/libhb/common.h index 712960248..41463c135 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -624,7 +624,7 @@ struct hb_title_s int video_codec; /* worker object id of video codec */ uint32_t video_stream_type; /* stream type from source stream */ int video_codec_param; /* codec specific config */ - const char *video_codec_name; + char *video_codec_name; int video_bitrate; const char *container_name; int data_rate; diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c index 87e829a75..b2f5af8c5 100644 --- a/libhb/decavcodec.c +++ b/libhb/decavcodec.c @@ -68,6 +68,7 @@ static void flushDelayQueue( hb_work_private_t *pv ); static int decavcodecInit( hb_work_object_t *, hb_job_t * ); static int decavcodecWork( hb_work_object_t *, hb_buffer_t **, hb_buffer_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 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; @@ -272,6 +273,10 @@ static void closePrivData( hb_work_private_t ** ppv ) { hb_avcodec_close( pv->context ); } + if ( free_av_context ) + { + av_free( pv->context ); + } if ( 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 ) { 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; } } @@ -560,6 +585,7 @@ static int decavcodecBSInfo( hb_work_object_t *w, const hb_buffer_t *buf, if ( parser != NULL ) av_parser_close( parser ); hb_avcodec_close( context ); + av_free( context ); return ret; } @@ -1662,7 +1688,7 @@ hb_work_object_t hb_decavcodecvi = "Video decoder (ffmpeg streams)", decavcodecviInit, decavcodecviWork, - decavcodecClose, + decavcodeciClose, decavcodecviInfo, decavcodecvBSInfo }; @@ -1673,7 +1699,7 @@ hb_work_object_t hb_decavcodecai = "Audio decoder (ffmpeg streams)", decavcodecviInit, decavcodecaiWork, - decavcodecClose, + decavcodeciClose, decavcodecInfo, decavcodecBSInfo }; diff --git a/libhb/decdca.c b/libhb/decdca.c index ed86be4b7..138024a6d 100644 --- a/libhb/decdca.c +++ b/libhb/decdca.c @@ -302,6 +302,7 @@ static int decdcaBSInfo( hb_work_object_t *w, const hb_buffer_t *b, if ( i >= b->size - 7 ) { /* didn't find DCA sync */ + dca_free( state ); 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; + dca_free( state ); return 1; } diff --git a/libhb/hb.c b/libhb/hb.c index ee5ce804b..a387dc917 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -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) ); } } + title_copy->video_codec_name = strdup( title->video_codec_name ); /* * 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->pause_lock ); + free( h->interjob ); + free( h ); *_h = NULL; } diff --git a/libhb/scan.c b/libhb/scan.c index fe7f0e176..34137c42b 100644 --- a/libhb/scan.c +++ b/libhb/scan.c @@ -188,6 +188,16 @@ static void ScanFunc( void * _data ) { /* TODO: free things */ 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; } @@ -195,6 +205,11 @@ static void ScanFunc( void * _data ) for( j = 0; j < hb_list_count( title->list_audio ); ) { 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 ) { hb_log( "scan: removing audio 0x%x because no bitrate found", @@ -203,11 +218,6 @@ static void ScanFunc( void * _data ) free( audio ); continue; } - if ( audio->priv.scan_cache ) - { - hb_fifo_flush( audio->priv.scan_cache ); - hb_fifo_close( &audio->priv.scan_cache ); - } j++; } @@ -449,7 +459,6 @@ static void most_common_info( info_list_t *info_list, hb_work_info_t *info ) biggest = i; } *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 ) { + free( info_list ); + free( crops ); return 0; } if (data->bd) @@ -639,6 +650,8 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title ) if( ! vid_buf ) { hb_log( "scan: could not get a decoded picture" ); + vid_decoder->close( vid_decoder ); + free( vid_decoder ); continue; } @@ -659,12 +672,13 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title ) free( vid_decoder ); continue; } - vid_decoder->close( vid_decoder ); - free( vid_decoder ); remember_info( info_list, &vid_info ); - title->video_codec_name = strdup( vid_info.name ); + if ( title->video_codec_name == NULL ) + { + title->video_codec_name = strdup( vid_info.name ); + } title->width = vid_info.width; title->height = vid_info.height; title->rate = vid_info.rate; @@ -813,6 +827,9 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title ) ++npreviews; skip_preview: + vid_decoder->close( vid_decoder ); + free( vid_decoder ); + /* Make sure we found audio rates and bitrates */ 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[3] = EVEN( crops->r[i] ); } - free( crops ); hb_log( "scan: %d previews, %dx%d, %.3f fps, autocrop = %d/%d/%d/%d, " "aspect %s, PAR %d:%d", @@ -907,6 +923,8 @@ skip_preview: title->detected_interlacing = 0; } } + free( crops ); + free( info_list ); 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 ) { /* didn't find any info */ + free( w ); return; } hb_fifo_flush( audio->priv.scan_cache ); |