From: Frédéric Yhuel Date: Wed, 10 Oct 2012 16:54:57 +0000 (+0200) Subject: Smooth Streaming: fix some memory leaks X-Git-Tag: 2.1.0-git~2586 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=70459ae3685e78c75c910de5e42cc67f76713868;p=vlc Smooth Streaming: fix some memory leaks Signed-off-by: Jean-Baptiste Kempf --- diff --git a/modules/stream_filter/smooth/smooth.c b/modules/stream_filter/smooth/smooth.c index 3e7d9a5333..9a4ad2090e 100644 --- a/modules/stream_filter/smooth/smooth.c +++ b/modules/stream_filter/smooth/smooth.c @@ -146,9 +146,7 @@ static int parse_Manifest( stream_t *s ) } const char *node; - char *stream_name = NULL; uint8_t *WaveFormatEx; - int stream_type = UNKNOWN_ES; sms_stream_t *sms = NULL; quality_level_t *ql = NULL; int64_t start_time = 0, duration = 0; @@ -192,15 +190,15 @@ static int parse_Manifest( stream_t *s ) if( !strcmp( name, "Type" ) ) { if( !strcmp( value, "video" ) ) - stream_type = VIDEO_ES; + sms->type = VIDEO_ES; else if( !strcmp( value, "audio" ) ) - stream_type = AUDIO_ES; + sms->type = AUDIO_ES; else if( !strcmp( value, "text" ) ) - stream_type = SPU_ES; + sms->type = SPU_ES; } if( !strcmp( name, "Name" ) ) - stream_name = strdup( value ); + sms->name = strdup( value ); if( !strcmp( name, "TimeScale" ) ) sms->timescale = strtoull( value, NULL, 10 ); if( !strcmp( name, "FourCC" ) ) @@ -222,18 +220,16 @@ static int parse_Manifest( stream_t *s ) if( sms && !sms->timescale ) sms->timescale = TIMESCALE; - if( !stream_name ) + if( !sms->name ) { - if( stream_type == VIDEO_ES ) - stream_name = strdup( "video" ); - else if( stream_type == AUDIO_ES ) - stream_name = strdup( "audio" ); - else if( stream_type == SPU_ES ) - stream_name = strdup( "text" ); + if( sms->type == VIDEO_ES ) + sms->name = strdup( "video" ); + else if( sms->type == AUDIO_ES ) + sms->name = strdup( "audio" ); + else if( sms->type == SPU_ES ) + sms->name = strdup( "text" ); } - sms->name = stream_name; - sms->type = stream_type; vlc_array_append( p_sys->sms_streams, sms ); } @@ -346,8 +342,6 @@ static int parse_Manifest( stream_t *s ) if( strcmp( node, "StreamIndex" ) ) break; - stream_name = NULL; - stream_type = UNKNOWN_ES; computed_start_time = 0; computed_duration = 0; loop_count = 0; @@ -502,7 +496,9 @@ static void Close( vlc_object_t *p_this ) sms_Free( sms ); } + sms_queue_free( p_sys->bws ); vlc_array_destroy( p_sys->sms_streams ); + vlc_array_destroy( p_sys->selected_st ); vlc_array_destroy( p_sys->download.chunks ); free( p_sys->base_url ); diff --git a/modules/stream_filter/smooth/smooth.h b/modules/stream_filter/smooth/smooth.h index dbc32edb9d..965fa0ebd8 100644 --- a/modules/stream_filter/smooth/smooth.h +++ b/modules/stream_filter/smooth/smooth.h @@ -165,6 +165,7 @@ struct stream_sys_t #define NO_MORE_CHUNKS ( !p_sys->b_live && \ no_more_chunks( p_sys->download.ck_index, p_sys->selected_st ) ) +void sms_queue_free( sms_queue_t* ); sms_queue_t *sms_queue_init( const int ); int sms_queue_put( sms_queue_t *, const uint64_t ); uint64_t sms_queue_avg( sms_queue_t *); diff --git a/modules/stream_filter/smooth/utils.c b/modules/stream_filter/smooth/utils.c index be27c039e1..d02d63c433 100644 --- a/modules/stream_filter/smooth/utils.c +++ b/modules/stream_filter/smooth/utils.c @@ -136,6 +136,8 @@ void sms_Free( sms_stream_t *sms ) vlc_array_destroy( sms->chunks ); } + free( sms->name ); + free( sms->url_template ); free( sms ); sms = NULL; } @@ -162,18 +164,37 @@ sms_queue_t *sms_queue_init( const int length ) return ret; } +void sms_queue_free( sms_queue_t* queue ) +{ + item_t *item = queue->first, *next = NULL; + while( item ) + { + next = item->next; + FREENULL( item ); + item = next; + } + FREENULL( queue ); +} + int sms_queue_put( sms_queue_t *queue, const uint64_t value ) { - item_t *last = queue->first; - int i = 0; - for( i = 0; i < queue->length - 1; i++ ) + /* Remove the last (and oldest) item */ + item_t *item, *prev; + int count = 0; + for( item = queue->first; item != NULL; item = item->next ) { - if( last ) - last = last->next; + count++; + if( count == queue->length ) + { + FREENULL( item ); + if( prev ) prev->next = NULL; + break; + } + else + prev = item; } - if( i == queue->length - 1 ) - FREENULL( last ); + /* Now insert the new item */ item_t *new = malloc( sizeof( item_t ) ); if( unlikely( !new ) ) return VLC_ENOMEM;