[vlc-devel] [RFC 06/38] demux/flac: replaced usage of xmalloc

Filip Roséen filip at videolabs.io
Mon Jun 27 13:43:17 CEST 2016


---
 modules/demux/flac.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/modules/demux/flac.c b/modules/demux/flac.c
index cf45308..b9981a0 100644
--- a/modules/demux/flac.c
+++ b/modules/demux/flac.c
@@ -412,7 +412,11 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
             return VLC_EGENERIC;
 
         *pi_int = p_sys->i_attachments;
-        *ppp_attach = xmalloc( sizeof(input_attachment_t*) * p_sys->i_attachments );
+        *ppp_attach = malloc( sizeof(input_attachment_t*) * p_sys->i_attachments );
+
+        if( unlikely( !*ppp_attach ) )
+            return VLC_ENOMEM;
+
         for( int i = 0; i < p_sys->i_attachments; i++ )
             (*ppp_attach)[i] = vlc_input_attachment_Duplicate( p_sys->attachments[i] );
         return VLC_SUCCESS;
@@ -506,9 +510,11 @@ static int  ReadMeta( demux_t *p_demux, uint8_t **pp_streaminfo, int *pi_streami
     *pp_streaminfo = NULL;
 
     /* Be sure we have seekpoint 0 */
-    flac_seekpoint_t *s = xmalloc( sizeof (*s) );
-    s->i_time_offset = 0;
-    s->i_byte_offset = 0;
+    flac_seekpoint_t *s = calloc( 1, sizeof (*s) );
+
+    if( unlikely( !s ) )
+        return VLC_ENOMEM;
+
     TAB_APPEND( p_sys->i_seekpoint, p_sys->seekpoint, s );
 
     uint8_t header[4];
@@ -617,7 +623,11 @@ static void ParseSeekTable( demux_t *p_demux, const uint8_t *p_data, int i_data,
         if( i_sample < 0 || i_sample >= INT64_MAX )
             continue;
 
-        s = xmalloc( sizeof (*s) );
+        s = malloc( sizeof( *s ) );
+
+        if( unlikely( !s ) )
+            break;
+
         s->i_time_offset = i_sample * CLOCK_FREQ / i_sample_rate;
         s->i_byte_offset = GetQWBE( &p_data[4+18*i+8] );
 
-- 
2.9.0



More information about the vlc-devel mailing list