[vlc-devel] [RFC 28/38] codec/speex: replaced usage of xmalloc
Filip Roséen
filip at videolabs.io
Mon Jun 27 13:43:39 CEST 2016
---
modules/codec/speex.c | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/modules/codec/speex.c b/modules/codec/speex.c
index 9adf28b..a80dc28 100644
--- a/modules/codec/speex.c
+++ b/modules/codec/speex.c
@@ -580,7 +580,15 @@ static void *ProcessPacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
block_t *p_new_block = NULL;
i_pcm_output_size = p_sys->p_header->frame_size;
- p_frame_holder = (short*)xmalloc( sizeof(short)*i_pcm_output_size );
+ p_frame_holder = malloc( sizeof(short)*i_pcm_output_size );
+
+ if( unlikely( !p_frame_holder ) )
+ {
+ if( p_block )
+ block_Release( p_block );
+
+ return NULL;
+ }
speex_bits_read_from( &p_sys->bits, (char*)p_oggpacket->packet,
p_oggpacket->bytes);
@@ -1043,7 +1051,13 @@ static int OpenEncoder( vlc_object_t *p_this )
p_sys->i_frame_size = p_sys->i_frame_length *
sizeof(int16_t) * p_enc->fmt_in.audio.i_channels;
- p_sys->p_buffer = xmalloc( p_sys->i_frame_size );
+ p_sys->p_buffer = malloc( p_sys->i_frame_size );
+
+ if( unlikely( !p_sys->p_buffer ) )
+ {
+ CloseEncoder( p_enc );
+ return VLC_ENOMEM;
+ }
/* Create and store headers */
pp_header[0] = speex_header_to_packet( &p_sys->header, &pi_header[0] );
@@ -1051,7 +1065,14 @@ static int OpenEncoder( vlc_object_t *p_this )
pi_header[1] = sizeof("ENCODER=VLC media player");
p_enc->fmt_out.i_extra = 3 * 2 + pi_header[0] + pi_header[1];
- p_extra = p_enc->fmt_out.p_extra = xmalloc( p_enc->fmt_out.i_extra );
+ p_extra = p_enc->fmt_out.p_extra = malloc( p_enc->fmt_out.i_extra );
+
+ if( unlikely( !p_extra ) )
+ {
+ CloseEncoder( p_enc );
+ return VLC_ENOMEM;
+ }
+
for( i = 0; i < 2; i++ )
{
*(p_extra++) = pi_header[i] >> 8;
--
2.9.0
More information about the vlc-devel
mailing list