From b955f8603cfe9a533abefa5b0bb5cbfe3c7eb59f Mon Sep 17 00:00:00 2001 From: Francois Cartegnie Date: Sat, 21 Mar 2015 18:48:06 +0100 Subject: [PATCH] mux: avi: fix leak on format failure --- modules/mux/avi.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/modules/mux/avi.c b/modules/mux/avi.c index 1cdea1dd2b..48d4ca24d1 100644 --- a/modules/mux/avi.c +++ b/modules/mux/avi.c @@ -317,14 +317,15 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) p_stream->p_bih = NULL; - p_stream->p_wf = malloc( sizeof( WAVEFORMATEX ) + - p_input->p_fmt->i_extra ); - if( !p_stream->p_wf ) + WAVEFORMATEX *p_wf = malloc( sizeof( WAVEFORMATEX ) + + p_input->p_fmt->i_extra ); + if( !p_wf ) { free( p_input->p_sys ); + p_input->p_sys = NULL; return VLC_ENOMEM; } -#define p_wf p_stream->p_wf + p_wf->cbSize = p_input->p_fmt->i_extra; if( p_wf->cbSize > 0 ) { @@ -390,9 +391,12 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) p_wf->nSamplesPerSec * p_wf->nChannels; break; default: + free( p_wf ); + free( p_input->p_sys ); + p_input->p_sys = NULL; return VLC_EGENERIC; } -#undef p_wf + p_stream->p_wf = p_wf; break; case VIDEO_ES: p_stream->i_cat = VIDEO_ES; @@ -405,14 +409,15 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) p_sys->i_stream_video = p_sys->i_streams; } p_stream->p_wf = NULL; - p_stream->p_bih = malloc( sizeof( VLC_BITMAPINFOHEADER ) + - p_input->p_fmt->i_extra ); - if( !p_stream->p_bih ) + VLC_BITMAPINFOHEADER *p_bih = malloc( sizeof( VLC_BITMAPINFOHEADER ) + + p_input->p_fmt->i_extra ); + if( !p_bih ) { free( p_input->p_sys ); + p_input->p_sys = NULL; return VLC_ENOMEM; } -#define p_bih p_stream->p_bih + p_bih->biSize = sizeof( VLC_BITMAPINFOHEADER ) + p_input->p_fmt->i_extra; if( p_input->p_fmt->i_extra > 0 ) @@ -439,9 +444,11 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) p_bih->biCompression = p_input->p_fmt->i_original_fourcc ?: p_input->p_fmt->i_codec; break; } -#undef p_bih + p_stream->p_bih = p_bih; break; default: + free( p_input->p_sys ); + p_input->p_sys = NULL; return( VLC_EGENERIC ); } p_stream->i_totalsize = 0; -- 2.39.2