[vlc-devel] commit: Check memory allocations. (Jean-Paul Saman )

git version control git at videolan.org
Fri Jun 20 16:37:54 CEST 2008


vlc | branch: master | Jean-Paul Saman <jpsaman at videolan.org> | Fri Jun 20 16:12:29 2008 +0200| [52ca31e6963b0f2c68ecd461959eb8aca9c25605]

Check memory allocations.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=52ca31e6963b0f2c68ecd461959eb8aca9c25605
---

 modules/demux/ps.c |    2 +
 modules/demux/ps.h |   54 ++++++++++++++++++++++++++++++++-------------------
 2 files changed, 36 insertions(+), 20 deletions(-)

diff --git a/modules/demux/ps.c b/modules/demux/ps.c
index fbd01a0..7ecf8d1 100644
--- a/modules/demux/ps.c
+++ b/modules/demux/ps.c
@@ -124,6 +124,7 @@ static int OpenCommon( vlc_object_t *p_this, bool b_force )
     p_demux->pf_demux = Demux;
     p_demux->pf_control = Control;
     p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
+    if( !p_sys ) return VLC_ENOMEM;
 
     /* Init p_sys */
     p_sys->i_mux_rate = 0;
@@ -559,6 +560,7 @@ static block_t *ps_pkt_read( stream_t *s, uint32_t i_code )
     const uint8_t *p_peek;
     int      i_peek = stream_Peek( s, &p_peek, 14 );
     int      i_size = ps_pkt_size( p_peek, i_peek );
+    VLC_UNUSED(i_code);
 
     if( i_size <= 6 && p_peek[3] > 0xba )
     {
diff --git a/modules/demux/ps.h b/modules/demux/ps.h
index a3559b9..191cce3 100644
--- a/modules/demux/ps.h
+++ b/modules/demux/ps.h
@@ -168,8 +168,11 @@ static inline int ps_track_fill( ps_track_t *tk, ps_psm_t *p_psm, int i_id )
     if( ps_id_to_lang( p_psm, i_id ) )
     {
         tk->fmt.psz_language = malloc( 4 );
-        memcpy( tk->fmt.psz_language, ps_id_to_lang( p_psm , i_id ), 3 );
-        tk->fmt.psz_language[3] = 0;
+        if( tk->fmt.psz_language )
+        {
+            memcpy( tk->fmt.psz_language, ps_id_to_lang( p_psm , i_id ), 3 );
+            tk->fmt.psz_language[3] = 0;
+        }
     }
 
     return VLC_SUCCESS;
@@ -534,6 +537,7 @@ static inline int ps_psm_fill( ps_psm_t *p_psm, block_t *p_pkt,
 
     while( i_es_base + 4 < i_length )
     {
+        ps_es_t **tmp_es;
         ps_es_t es;
         es.lang[0] = es.lang[1] = es.lang[2] = 0;
 
@@ -556,31 +560,41 @@ static inline int ps_psm_fill( ps_psm_t *p_psm, block_t *p_pkt,
             int i = 0;
 
             es.p_descriptor = malloc( i_info_length );
-            memcpy( es.p_descriptor, p_buffer + i_es_base + 4, i_info_length);
-
-            while( i <= es.i_descriptor - 2 )
+            if( es.p_descriptor )
             {
-                /* Look for the ISO639 language descriptor */
-                if( es.p_descriptor[i] != 0x0a )
-                {
-                    i += es.p_descriptor[i+1] + 2;
-                    continue;
-                }
+                memcpy( es.p_descriptor, p_buffer + i_es_base + 4, i_info_length);
 
-                if( i <= es.i_descriptor - 6 )
+                while( i <= es.i_descriptor - 2 )
                 {
-                    es.lang[0] = es.p_descriptor[i+2];
-                    es.lang[1] = es.p_descriptor[i+3];
-                    es.lang[2] = es.p_descriptor[i+4];
+                    /* Look for the ISO639 language descriptor */
+                    if( es.p_descriptor[i] != 0x0a )
+                    {
+                        i += es.p_descriptor[i+1] + 2;
+                        continue;
+                    }
+
+                    if( i <= es.i_descriptor - 6 )
+                    {
+                        es.lang[0] = es.p_descriptor[i+2];
+                        es.lang[1] = es.p_descriptor[i+3];
+                        es.lang[2] = es.p_descriptor[i+4];
+                    }
+                    break;
                 }
-                break;
             }
         }
 
-        p_psm->es = realloc( p_psm->es, sizeof(ps_es_t *) * (p_psm->i_es+1) );
-        p_psm->es[p_psm->i_es] = malloc( sizeof(ps_es_t) );
-        *p_psm->es[p_psm->i_es++] = es;
-        i_es_base += 4 + i_info_length;
+        tmp_es = realloc( p_psm->es, sizeof(ps_es_t *) * (p_psm->i_es+1) );
+        if( tmp_es )
+        {
+            p_psm->es = tmp_es;
+            p_psm->es[p_psm->i_es] = malloc( sizeof(ps_es_t) );
+            if( p_psm->es[p_psm->i_es] )
+            {
+                *p_psm->es[p_psm->i_es++] = es;
+                i_es_base += 4 + i_info_length;
+            }
+        }
     }
 
     /* TODO: CRC */




More information about the vlc-devel mailing list