[vlc-devel] [RFC 07/38] demux/ty: removed usage of xmalloc

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


in order to remove usage of xmalloc some additional changes was required
so that a memory-allocation error propogates all the way up to where it
is needed.
---
 modules/demux/ty.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/modules/demux/ty.c b/modules/demux/ty.c
index be0753e..8b87178 100644
--- a/modules/demux/ty.c
+++ b/modules/demux/ty.c
@@ -1078,7 +1078,9 @@ static int ty_stream_seek_pct(demux_t *p_demux, double seek_pct)
     }
     /* load the chunk */
     p_sys->i_stuff_cnt = 0;
-    get_chunk_header(p_demux);
+
+    if( !get_chunk_header(p_demux) );
+      return VLC_EGENERIC;
 
     /* seek within the chunk to get roughly to where we want */
     p_sys->i_cur_rec = (int)
@@ -1745,6 +1747,10 @@ static void analyze_chunk(demux_t *p_demux, const uint8_t *p_chunk)
     p_chunk += 4;       /* skip past rec count & SEQ bytes */
     //msg_Dbg(p_demux, "probe: chunk has %d recs", i_num_recs);
     p_hdrs = parse_chunk_headers(p_chunk, i_num_recs, &i_payload_size);
+
+    if( p_hdrs == NULL )
+        return;
+
     /* scan headers.
      * 1. check video packets.  Presence of 0x6e0 means S1.
      *    No 6e0 but have be0 means S2.
@@ -1897,7 +1903,9 @@ static int get_chunk_header(demux_t *p_demux)
     stream_Read( p_demux->s, NULL, 4 );
 
     /* read the record headers into a temp buffer */
-    p_hdr_buf = xmalloc(i_num_recs * 16);
+    if( ( p_hdr_buf = malloc( i_num_recs * 16 ) ) == NULL )
+        return 0;
+
     if (stream_Read(p_demux->s, p_hdr_buf, i_num_recs * 16) < i_num_recs * 16) {
         free( p_hdr_buf );
         p_sys->eof = true;
@@ -1908,6 +1916,9 @@ static int get_chunk_header(demux_t *p_demux)
             &i_payload_size);
     free(p_hdr_buf);
 
+    if( p_sys->rec_hdrs == NULL )
+        return 0;
+
     p_sys->i_stuff_cnt = CHUNK_SIZE - 4 -
         (p_sys->i_num_recs * 16) - i_payload_size;
     if (p_sys->i_stuff_cnt > 0)
@@ -1924,7 +1935,9 @@ static ty_rec_hdr_t *parse_chunk_headers( const uint8_t *p_buf,
     ty_rec_hdr_t *p_hdrs, *p_rec_hdr;
 
     *pi_payload_size = 0;
-    p_hdrs = xmalloc(i_num_recs * sizeof(ty_rec_hdr_t));
+
+    if( ( p_hdrs = malloc( i_num_recs * sizeof( *p_hdrs ) ) ) == NULL )
+        return NULL;
 
     for (i = 0; i < i_num_recs; i++)
     {
-- 
2.9.0



More information about the vlc-devel mailing list