From: RĂ©mi Duraffort Date: Wed, 20 Aug 2008 20:55:04 +0000 (+0200) Subject: Check malloc return value and avoid memleaks. X-Git-Tag: 0.9.0~160 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=6b44362dc4c8d60f6877e674666eaf49f22a0dfd;p=vlc Check malloc return value and avoid memleaks. --- diff --git a/modules/mux/avi.c b/modules/mux/avi.c index 31b13153ab..4514e72794 100644 --- a/modules/mux/avi.c +++ b/modules/mux/avi.c @@ -143,6 +143,8 @@ static int Open( vlc_object_t *p_this ) msg_Dbg( p_mux, "AVI muxer opened" ); p_sys = malloc( sizeof( sout_mux_sys_t ) ); + if( !p_sys ) + return VLC_ENOMEM; p_sys->i_streams = 0; p_sys->i_stream_video = -1; p_sys->i_movi_size = 0; @@ -151,6 +153,11 @@ static int Open( vlc_object_t *p_this ) p_sys->idx1.i_entry_max = 10000; p_sys->idx1.entry = calloc( p_sys->idx1.i_entry_max, sizeof( avi_idx1_entry_t ) ); + if( !p_sys->idx1.entry ) + { + free( p_sys ); + return VLC_ENOMEM; + } p_sys->b_write_header = true; @@ -253,11 +260,13 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) if( p_sys->i_streams >= 100 ) { msg_Err( p_mux, "too many streams" ); - return( -1 ); + return VLC_EGENERIC; } msg_Dbg( p_mux, "adding input" ); p_input->p_sys = malloc( sizeof( int ) ); + if( !p_input->p_sys ) + return VLC_ENOMEM; *((int*)p_input->p_sys) = p_sys->i_streams; p_stream = &p_sys->stream[p_sys->i_streams]; @@ -275,6 +284,11 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) p_stream->p_wf = malloc( sizeof( WAVEFORMATEX ) + p_input->p_fmt->i_extra ); + if( !p_stream->p_wf ) + { + free( p_input->p_sys ); + return VLC_ENOMEM; + } #define p_wf p_stream->p_wf p_wf->cbSize = p_input->p_fmt->i_extra; if( p_wf->cbSize > 0 ) @@ -349,6 +363,11 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) p_stream->p_wf = NULL; p_stream->p_bih = malloc( sizeof( BITMAPINFOHEADER ) + p_input->p_fmt->i_extra ); + if( !p_stream->p_bih ) + { + free( p_input->p_sys ); + return VLC_ENOMEM; + } #define p_bih p_stream->p_bih p_bih->biSize = sizeof( BITMAPINFOHEADER ) + p_input->p_fmt->i_extra; @@ -395,11 +414,10 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) static int DelStream( sout_mux_t *p_mux, sout_input_t *p_input ) { - msg_Dbg( p_mux, "removing input" ); free( p_input->p_sys ); - return( 0 ); + return 0; } static int Mux ( sout_mux_t *p_mux ) diff --git a/modules/mux/dummy.c b/modules/mux/dummy.c index a62b3587e8..56f5e3018c 100644 --- a/modules/mux/dummy.c +++ b/modules/mux/dummy.c @@ -84,6 +84,8 @@ static int Open( vlc_object_t *p_this ) p_mux->pf_mux = Mux; p_mux->p_sys = p_sys = malloc( sizeof( sout_mux_sys_t ) ); + if( !p_sys ) + return VLC_ENOMEM; p_sys->b_header = true; return VLC_SUCCESS; diff --git a/modules/mux/mp4.c b/modules/mux/mp4.c index 73862581d4..d6c70ac84e 100644 --- a/modules/mux/mp4.c +++ b/modules/mux/mp4.c @@ -193,6 +193,8 @@ static int Open( vlc_object_t *p_this ) p_mux->pf_delstream = DelStream; p_mux->pf_mux = Mux; p_mux->p_sys = p_sys = malloc( sizeof( sout_mux_sys_t ) ); + if( !p_sys ) + return VLC_ENOMEM; p_sys->i_pos = 0; p_sys->i_nb_streams = 0; p_sys->pp_streams = NULL; @@ -422,6 +424,8 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input ) } p_stream = malloc( sizeof( mp4_stream_t ) ); + if( !p_stream ) + return VLC_ENOMEM; es_format_Copy( &p_stream->fmt, p_input->p_fmt ); p_stream->i_track_id = p_sys->i_nb_streams + 1; p_stream->i_length_neg = 0;