]> git.sesse.net Git - vlc/blobdiff - modules/demux/real.c
Remove useless test before a free (again).
[vlc] / modules / demux / real.c
index a3cc2af3998984ae35b6e40896c75b1dd74f79d5..8f382873052533812eb0b8cbdb664de50c10fb79 100644 (file)
@@ -149,8 +149,14 @@ static int Open( vlc_object_t *p_this )
     /* Fill p_demux field */
     p_demux->pf_demux = Demux;
     p_demux->pf_control = Control;
+
     p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
+    if( p_sys == NULL )
+    {
+        return VLC_ENOMEM;
+    }
     memset( p_sys, 0, sizeof( demux_sys_t ) );
+
     p_sys->i_data_offset = 0;
     p_sys->i_track = 0;
     p_sys->track   = NULL;
@@ -210,10 +216,10 @@ static void Close( vlc_object_t *p_this )
         free( tk );
     }
 
-    if( p_sys->psz_title ) free( p_sys->psz_title );
-    if( p_sys->psz_artist ) free( p_sys->psz_artist );
-    if( p_sys->psz_copyright ) free( p_sys->psz_copyright );
-    if( p_sys->psz_description ) free( p_sys->psz_description );
+    free( p_sys->psz_title );
+    free( p_sys->psz_artist );
+    free( p_sys->psz_copyright );
+    free( p_sys->psz_description );
 
     if( p_sys->i_track > 0 ) free( p_sys->track );
     free( p_sys );
@@ -817,10 +823,9 @@ static int HeaderRead( demux_t *p_demux )
                 stream_Read( p_demux->s, psz, i_len );
                 psz[i_len] = '\0';
 
-                msg_Dbg( p_demux, "    - title=`%s'", psz );
                 EnsureUTF8( psz );
-                asprintf( &p_sys->psz_title, psz );
-                free( psz );
+                msg_Dbg( p_demux, "    - title=`%s'", psz );
+                p_sys->psz_title = psz;
                 i_skip -= i_len;
             }
             i_skip -= 2;
@@ -832,10 +837,9 @@ static int HeaderRead( demux_t *p_demux )
                 stream_Read( p_demux->s, psz, i_len );
                 psz[i_len] = '\0';
 
-                msg_Dbg( p_demux, "    - author=`%s'", psz );
                 EnsureUTF8( psz );
-                asprintf( &p_sys->psz_artist, psz );
-                free( psz );
+                msg_Dbg( p_demux, "    - author=`%s'", psz );
+                p_sys->psz_artist = psz;
                 i_skip -= i_len;
             }
             i_skip -= 2;
@@ -847,10 +851,9 @@ static int HeaderRead( demux_t *p_demux )
                 stream_Read( p_demux->s, psz, i_len );
                 psz[i_len] = '\0';
 
-                msg_Dbg( p_demux, "    - copyright=`%s'", psz );
                 EnsureUTF8( psz );
-                asprintf( &p_sys->psz_copyright, psz );
-                free( psz );
+                msg_Dbg( p_demux, "    - copyright=`%s'", psz );
+                p_sys->psz_copyright = psz;
                 i_skip -= i_len;
             }
             i_skip -= 2;
@@ -862,10 +865,9 @@ static int HeaderRead( demux_t *p_demux )
                 stream_Read( p_demux->s, psz, i_len );
                 psz[i_len] = '\0';
 
-                msg_Dbg( p_demux, "    - comment=`%s'", psz );
                 EnsureUTF8( psz );
-                asprintf( &p_sys->psz_description, psz );
-                free( psz );
+                msg_Dbg( p_demux, "    - comment=`%s'", psz );
+                p_sys->psz_description = psz;
                 i_skip -= i_len;
             }
             i_skip -= 2;
@@ -1048,10 +1050,9 @@ static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num )
                 memcpy( psz, p_peek, i_len );
                 psz[i_len] = '\0';
 
-                msg_Dbg( p_demux, "    - title=`%s'", psz );
                 EnsureUTF8( psz );
-                asprintf( &p_sys->psz_title, psz );
-                free( psz );
+                msg_Dbg( p_demux, "    - title=`%s'", psz );
+                p_sys->psz_title = psz;
             }
             p_peek += i_len;
 
@@ -1063,10 +1064,9 @@ static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num )
                 memcpy( psz, p_peek, i_len );
                 psz[i_len] = '\0';
 
-                msg_Dbg( p_demux, "    - artist=`%s'", psz );
                 EnsureUTF8( psz );
-                asprintf( &p_sys->psz_artist, psz );
-                free( psz );
+                msg_Dbg( p_demux, "    - artist=`%s'", psz );
+                p_sys->psz_artist = psz;
             }
             p_peek += i_len;
 
@@ -1078,10 +1078,9 @@ static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num )
                 memcpy( psz, p_peek, i_len );
                 psz[i_len] = '\0';
 
-                msg_Dbg( p_demux, "    - Copyright=`%s'", psz );
                 EnsureUTF8( psz );
-                asprintf( &p_sys->psz_copyright, psz );
-                free( psz );
+                msg_Dbg( p_demux, "    - Copyright=`%s'", psz );
+                p_sys->psz_copyright = psz;
             }
             p_peek += i_len;
 
@@ -1093,10 +1092,9 @@ static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num )
                 memcpy( psz, p_peek, i_len );
                 psz[i_len] = '\0';
 
-                msg_Dbg( p_demux, "    - Comment=`%s'", psz );
                 EnsureUTF8( psz );
-                asprintf( &p_sys->psz_description, psz );
-                free( psz );
+                msg_Dbg( p_demux, "    - Comment=`%s'", psz );
+                p_sys->psz_description = psz;
             }
             /* This might be unusefull */
             p_peek += i_len;
@@ -1181,14 +1179,19 @@ static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num )
 
         case VLC_FOURCC( 'r','a','a','c' ):
         case VLC_FOURCC( 'r','a','c','p' ):
+            fmt.i_codec = VLC_FOURCC( 'm','p','4','a' );
+
             if( fmt.i_extra > 0 ) { fmt.i_extra--; p_peek++; }
             if( fmt.i_extra > 0 )
             {
                 fmt.p_extra = malloc( fmt.i_extra );
+                if( fmt.p_extra == NULL )
+                {
+                    msg_Err( p_demux, "Error in the extra data" );
+                    return VLC_EGENERIC;
+                }
                 memcpy( fmt.p_extra, p_peek, fmt.i_extra );
             }
-
-            fmt.i_codec = VLC_FOURCC( 'm','p','4','a' );
             break;
 
         case VLC_FOURCC('s','i','p','r'):
@@ -1199,9 +1202,17 @@ static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num )
                 fmt.audio.i_blockalign = i_subpacket_size;
             else
                 fmt.audio.i_blockalign = i_coded_frame_size;
-            if( !fmt.i_extra ) break;
-            fmt.p_extra = malloc( fmt.i_extra );
-            memcpy( fmt.p_extra, p_peek, fmt.i_extra );
+
+            if( fmt.i_extra > 0 )
+            {
+                fmt.p_extra = malloc( fmt.i_extra );
+                if( fmt.p_extra == NULL )
+                {
+                    msg_Err( p_demux, "Error in the extra data" );
+                    return VLC_EGENERIC;
+                }
+                memcpy( fmt.p_extra, p_peek, fmt.i_extra );
+            }
             break;
 
         case VLC_FOURCC('r','a','l','f'):
@@ -1252,6 +1263,14 @@ static int ReadCodecSpecificData( demux_t *p_demux, int i_len, int i_num )
                     calloc( tk->i_subpackets, sizeof(block_t *) );
             }
 
+            /* Check if the calloc went correctly */
+            if( tk->p_subpackets == NULL )
+            {
+                tk->i_subpackets = 0;
+                msg_Err( p_demux, "Can't alloc subpacket" );
+                return VLC_EGENERIC;
+            }
+
             tk->p_es = es_out_Add( p_demux->out, &fmt );
 
             TAB_APPEND( p_sys->i_track, p_sys->track, tk );