[vlc-devel] [PATCH 1/1] stream_filter: smooth: fix leaks (cid #1251056)
Jean-Baptiste Kempf
jb at videolan.org
Mon Nov 10 19:51:51 CET 2014
LSTM.
Le 05/11/2014 15:12, Tristan Matthews a écrit :
> ---
> modules/stream_filter/smooth/smooth.c | 53 ++++++++++++++++++++---------------
> 1 file changed, 30 insertions(+), 23 deletions(-)
>
> diff --git a/modules/stream_filter/smooth/smooth.c b/modules/stream_filter/smooth/smooth.c
> index f876778..eee774d 100644
> --- a/modules/stream_filter/smooth/smooth.c
> +++ b/modules/stream_filter/smooth/smooth.c
> @@ -116,6 +116,16 @@ static void print_chunk( stream_t *s, chunk_t *ck )
> }
> #endif
>
> +static void cleanup_attributes(custom_attrs_t **cp)
> +{
> + if( !*cp )
> + return;
> +
> + free( (*cp)->psz_key );
> + free( (*cp)->psz_value );
> + FREENULL( *cp );
> +}
> +
> static int parse_Manifest( stream_t *s )
> {
> stream_sys_t *p_sys = s->p_sys;
> @@ -152,6 +162,7 @@ static int parse_Manifest( stream_t *s )
> unsigned next_qid = 1;
> int loop_count = 0;
> bool b_weird = false;
> + int ret = VLC_SUCCESS;
>
> #define TIMESCALE 10000000
> while( (type = xml_ReaderNextNode( vlc_reader, &node )) > 0 )
> @@ -180,9 +191,8 @@ static int parse_Manifest( stream_t *s )
> sms = sms_New();
> if( unlikely( !sms ) )
> {
> - xml_ReaderDelete( vlc_reader );
> - xml_Delete( vlc_xml );
> - return VLC_ENOMEM;
> + ret = VLC_ENOMEM;
> + goto cleanup;
> }
> sms->id = next_track_id;
> next_track_id++;
> @@ -238,6 +248,11 @@ static int parse_Manifest( stream_t *s )
> if (!sms || !ql || cp)
> break;
> cp = (custom_attrs_t *) calloc( 1, sizeof(*cp) );
> + if( unlikely( !cp ) )
> + {
> + ret = VLC_ENOMEM;
> + goto cleanup;
> + }
> }
> else if ( !strcmp( node, "Attribute" ) )
> {
> @@ -260,10 +275,8 @@ static int parse_Manifest( stream_t *s )
> ql = ql_New();
> if( !ql )
> {
> - sms_Free( sms );
> - xml_ReaderDelete( vlc_reader );
> - xml_Delete( vlc_xml );
> - return VLC_ENOMEM;
> + ret = VLC_ENOMEM;
> + goto cleanup;
> }
> ql->id = next_qid;
> next_qid++;
> @@ -366,10 +379,8 @@ static int parse_Manifest( stream_t *s )
> if( unlikely( chunk_New( sms, computed_duration,
> computed_start_time ) == NULL ) )
> {
> - sms_Free( sms );
> - xml_ReaderDelete( vlc_reader );
> - xml_Delete( vlc_xml );
> - return VLC_ENOMEM;
> + ret = VLC_ENOMEM;
> + goto cleanup;
> }
> if( b_weird && start_time != -1 )
> computed_start_time = start_time;
> @@ -389,9 +400,7 @@ static int parse_Manifest( stream_t *s )
> {
> if( !cp->psz_key || !cp->psz_value )
> {
> - free( cp->psz_key );
> - free( cp->psz_value );
> - FREENULL( cp );
> + cleanup_attributes( &cp );
> }
> }
> else if( strcmp( node, "StreamIndex" ) )
> @@ -405,10 +414,8 @@ static int parse_Manifest( stream_t *s )
> loop_count = 0;
> if( b_weird && !chunk_New( sms, computed_duration, computed_start_time ) )
> {
> - sms_Free( sms );
> - xml_ReaderDelete( vlc_reader );
> - xml_Delete( vlc_xml );
> - return VLC_ENOMEM;
> + ret = VLC_ENOMEM;
> + goto cleanup;
> }
>
> b_weird = false;
> @@ -424,19 +431,19 @@ static int parse_Manifest( stream_t *s )
> case XML_READER_TEXT:
> break;
> default:
> - sms_Free( sms );
> - xml_ReaderDelete( vlc_reader );
> - xml_Delete( vlc_xml );
> - return VLC_EGENERIC;
> + ret = VLC_EGENERIC;
> + goto cleanup;
> }
> }
> #undef TIMESCALE
>
> +cleanup:
> + cleanup_attributes( &cp );
> sms_Free( sms );
> xml_ReaderDelete( vlc_reader );
> xml_Delete( vlc_xml );
>
> - return VLC_SUCCESS;
> + return ret;
> }
>
> static void SysCleanup( stream_sys_t *p_sys )
>
--
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device
More information about the vlc-devel
mailing list