summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2012-09-13 20:13:59 +0000
committerjstebbins <[email protected]>2012-09-13 20:13:59 +0000
commit8329bf01460521587889fd4133f76b32ccf13217 (patch)
treec0758b2c843c05b03ab1ad93857c6045ad7c0a91 /libhb
parentae8dee43bbcd12b5a4a532c7f4f65bf912479428 (diff)
libhb: fix a collection of small memory leaks
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4963 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r--libhb/audio_resample.c2
-rw-r--r--libhb/decavcodec.c10
-rw-r--r--libhb/decomb.c3
-rw-r--r--libhb/dvdnav.c2
-rw-r--r--libhb/fifo.c4
-rw-r--r--libhb/stream.c7
-rw-r--r--libhb/sync.c11
-rw-r--r--libhb/taskset.c8
-rw-r--r--libhb/work.c4
9 files changed, 39 insertions, 12 deletions
diff --git a/libhb/audio_resample.c b/libhb/audio_resample.c
index ce80bc5fe..bd9cbf61c 100644
--- a/libhb/audio_resample.c
+++ b/libhb/audio_resample.c
@@ -15,7 +15,7 @@ hb_audio_resample_t* hb_audio_resample_init(enum AVSampleFormat sample_fmt,
int hb_amixdown, int do_remix,
int normalize_mix_level)
{
- hb_audio_resample_t *resample = malloc(sizeof(hb_audio_resample_t));
+ hb_audio_resample_t *resample = calloc(1, sizeof(hb_audio_resample_t));
if (resample == NULL)
{
hb_error("hb_audio_resample_init: failed to allocate resample");
diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c
index 59ffee86c..b9e87b4eb 100644
--- a/libhb/decavcodec.c
+++ b/libhb/decavcodec.c
@@ -257,6 +257,7 @@ static void closePrivData( hb_work_private_t ** ppv )
}
if ( pv->context )
{
+ av_freep( &pv->context->extradata );
av_free( pv->context );
}
if ( pv->list )
@@ -1142,6 +1143,14 @@ static int decavcodecvWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
*buf_out = hb_buffer_init( 0 );;
return HB_WORK_DONE;
}
+ // Note that there is currently a small memory leak in libav at this
+ // point. pv->context->priv_data gets allocated by
+ // avcodec_alloc_context3(), then avcodec_get_context_defaults3()
+ // memsets the context and looses the pointer.
+ //
+ // avcodec_get_context_defaults3() looks as if they intended for
+ // it to preserve any existing priv_data because they test the pointer
+ // before allocating new memory, but the memset has already cleared it.
avcodec_get_context_defaults3( pv->context, codec );
init_video_avcodec_context( pv );
if ( setup_extradata( w, in ) )
@@ -1387,6 +1396,7 @@ static void decavcodecvFlush( hb_work_object_t *w )
{
pv->video_codec_opened = 0;
hb_avcodec_close( pv->context );
+ av_freep( &pv->context->extradata );
if ( pv->parser )
{
av_parser_close(pv->parser);
diff --git a/libhb/decomb.c b/libhb/decomb.c
index e931db020..c4e5346e4 100644
--- a/libhb/decomb.c
+++ b/libhb/decomb.c
@@ -2470,6 +2470,7 @@ static void hb_decomb_close( hb_filter_object_t * filter )
taskset_fini( &pv->yadif_taskset );
taskset_fini( &pv->decomb_filter_taskset );
+ taskset_fini( &pv->decomb_check_taskset );
if( pv->mode & MODE_FILTER )
{
@@ -2523,6 +2524,8 @@ static void hb_decomb_close( hb_filter_object_t * filter )
if (pv->tmpc) eedi2_aligned_free(pv->tmpc);
}
+ free(pv->block_score);
+
/*
* free memory for yadif structs
*/
diff --git a/libhb/dvdnav.c b/libhb/dvdnav.c
index e7257a17b..d38017205 100644
--- a/libhb/dvdnav.c
+++ b/libhb/dvdnav.c
@@ -1822,6 +1822,8 @@ static void hb_dvdnav_close( hb_dvd_t ** _d )
if( d->vmg ) ifoClose( d->vmg );
if( d->reader ) DVDClose( d->reader );
+ free(d->path);
+
free( d );
*_d = NULL;
}
diff --git a/libhb/fifo.c b/libhb/fifo.c
index 1f0d2ef97..6d11551f9 100644
--- a/libhb/fifo.c
+++ b/libhb/fifo.c
@@ -239,9 +239,9 @@ void hb_buffer_pool_free( void )
count = 0;
while( ( b = hb_fifo_get(buffers.pool[i]) ) )
{
- freed += b->alloc;
if( b->data )
{
+ freed += b->alloc;
free( b->data );
}
free( b );
@@ -342,7 +342,7 @@ void hb_buffer_realloc( hb_buffer_t * b, int size )
{
if ( size > b->alloc || b->data == NULL )
{
- uint32_t orig = b->alloc;
+ uint32_t orig = b->data != NULL ? b->alloc : 0;
size = size_to_pool( size )->buffer_size;
b->data = realloc( b->data, size );
b->alloc = size;
diff --git a/libhb/stream.c b/libhb/stream.c
index 4dd4a4e2a..ede9f33d3 100644
--- a/libhb/stream.c
+++ b/libhb/stream.c
@@ -4365,13 +4365,19 @@ static void hb_ts_resolve_pid_types(hb_stream_t *stream)
total_size += buf->size;
if ( total_size > HB_MAX_PROBE_SIZE * 2 )
+ {
+ hb_buffer_close(&buf);
break;
+ }
int idx;
idx = index_of_id( stream, buf->s.id );
if (idx < 0 || stream->pes.list[idx].stream_kind != U )
+ {
+ hb_buffer_close(&buf);
continue;
+ }
hb_pes_stream_t *pes = &stream->pes.list[idx];
@@ -4389,6 +4395,7 @@ static void hb_ts_resolve_pid_types(hb_stream_t *stream)
pes->codec_name, pes->stream_id, pes->stream_id_ext);
}
}
+ hb_buffer_close(&buf);
}
// Clean up any probe buffers and set all remaining unknown
// streams to 'kind' N
diff --git a/libhb/sync.c b/libhb/sync.c
index 9c202c250..f5ef07776 100644
--- a/libhb/sync.c
+++ b/libhb/sync.c
@@ -234,7 +234,9 @@ void syncVideoClose( hb_work_object_t * w )
if ( --pv->common->ref == 0 )
{
hb_unlock( pv->common->mutex );
+ hb_cond_close( &pv->common->next_frame );
hb_lock_close( &pv->common->mutex );
+ free( pv->common->first_pts );
free( pv->common );
}
else
@@ -360,12 +362,12 @@ int syncVideoWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
if( !sync->cur )
{
sync->cur = next;
- if( sync->cur->size == 0 )
+ if (next->size == 0)
{
/* we got an end-of-stream as our first video packet?
* Feed it downstream & signal that we're done.
*/
- *buf_out = hb_buffer_init( 0 );
+ *buf_out = next;
pv->common->start_found = 1;
pv->common->first_pts[0] = INT64_MAX - 1;
@@ -666,7 +668,9 @@ void syncAudioClose( hb_work_object_t * w )
if ( --pv->common->ref == 0 )
{
hb_unlock( pv->common->mutex );
+ hb_cond_close( &pv->common->next_frame );
hb_lock_close( &pv->common->mutex );
+ free( pv->common->first_pts );
free( pv->common );
}
else
@@ -940,6 +944,7 @@ static void InitAudio( hb_job_t * job, hb_sync_common_t * common, int i )
default:
{
// Never gets here
+ codec = NULL; // Silence compiler warning
} break;
}
@@ -1292,7 +1297,7 @@ static void UpdateSearchState( hb_work_object_t * w, int64_t start )
}
if (now > sync->st_first)
{
- int eta;
+ int eta = 0;
if ( pv->job->frame_to_start )
{
diff --git a/libhb/taskset.c b/libhb/taskset.c
index 35944175b..aced5dbc5 100644
--- a/libhb/taskset.c
+++ b/libhb/taskset.c
@@ -107,14 +107,14 @@ fail:
free( ts->task_complete_bitmap );
/* FALL THROUGH */
case 3:
- free( ts->task_begin_bitmap );
+ free( ts->task_begin_bitmap );
/* FALL THROUGH */
case 2:
- if( ts->task_threads_args == NULL )
+ if( ts->task_threads_args == NULL )
free( ts->task_threads_args );
/* FALL THROUGH */
case 1:
- free( ts->task_threads );
+ free( ts->task_threads );
/* FALL THROUGH */
case 0:
break;
@@ -124,7 +124,7 @@ fail:
int
taskset_thread_spawn( taskset_t *ts, int thr_idx, const char *descr,
- thread_func_t *func, int priority )
+ thread_func_t *func, int priority )
{
ts->task_threads[thr_idx] = hb_thread_init( descr, func,
taskset_thread_args( ts, thr_idx ),
diff --git a/libhb/work.c b/libhb/work.c
index 9dffb5f46..858156f45 100644
--- a/libhb/work.c
+++ b/libhb/work.c
@@ -750,8 +750,8 @@ static void do_job( hb_job_t * job )
job->fifo_mpeg2 = hb_fifo_init( FIFO_LARGE, FIFO_LARGE_WAKE );
job->fifo_raw = hb_fifo_init( FIFO_SMALL, FIFO_SMALL_WAKE );
job->fifo_sync = hb_fifo_init( FIFO_SMALL, FIFO_SMALL_WAKE );
- job->fifo_render = hb_fifo_init( FIFO_SMALL, FIFO_SMALL_WAKE );
job->fifo_mpeg4 = hb_fifo_init( FIFO_LARGE, FIFO_LARGE_WAKE );
+ job->fifo_render = NULL; // Attached to filter chain
/* Audio fifos must be initialized before sync */
if (!job->indepth_scan)
@@ -1324,7 +1324,6 @@ cleanup:
hb_fifo_close( &job->fifo_mpeg2 );
hb_fifo_close( &job->fifo_raw );
hb_fifo_close( &job->fifo_sync );
- hb_fifo_close( &job->fifo_render );
hb_fifo_close( &job->fifo_mpeg4 );
for( i = 0; i < hb_list_count( title->list_subtitle ); i++ )
@@ -1430,6 +1429,7 @@ cleanup:
for( i = 0; i < hb_list_count( job->list_filter ); i++ )
{
hb_filter_object_t * filter = hb_list_item( job->list_filter, i );
+ hb_fifo_close( &filter->fifo_out );
hb_filter_close( &filter );
}
hb_list_close( &job->list_filter );