[vlc-devel] commit: Fix use of realloc(). (Jean-Paul Saman )

git version control git at videolan.org
Mon Nov 24 15:06:36 CET 2008


vlc | branch: 0.8.6-bugfix | Jean-Paul Saman <jpsaman at videolan.org> | Thu Nov 13 09:54:06 2008 +0100| [5b50a2f332fe0582de9b9f461ec997d6f9a3ee4b] | committer: Jean-Paul Saman 

Fix use of realloc().

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

 modules/access/mms/mmstu.c |   66 ++++++++++++++++++++++++++++----------------
 1 files changed, 42 insertions(+), 24 deletions(-)

diff --git a/modules/access/mms/mmstu.c b/modules/access/mms/mmstu.c
index df5ec78..4e1eedd 100644
--- a/modules/access/mms/mmstu.c
+++ b/modules/access/mms/mmstu.c
@@ -126,7 +126,8 @@ int  E_(MMSTUOpen)( access_t *p_access )
     p_access->info.i_title = 0;
     p_access->info.i_seekpoint = 0;
     p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) );
-    if( !p_sys ) return VLC_ENOMEM;
+    if( !p_sys )
+         return VLC_ENOMEM;
     memset( p_sys, 0, sizeof( access_sys_t ) );
 
     p_sys->i_timeout = var_CreateGetInteger( p_access, "mms-timeout" );
@@ -294,7 +295,6 @@ static int Control( access_t *p_access, int i_query, va_list args )
         case ACCESS_SET_PRIVATE_ID_STATE:
             return VLC_EGENERIC;
 
-
         default:
             msg_Warn( p_access, "unimplemented query in control" );
             return VLC_EGENERIC;
@@ -318,7 +318,6 @@ static int Seek( access_t * p_access, int64_t i_pos )
 
     if( i_pos < p_sys->i_header)
     {
-
         if( p_access->info.i_pos < p_sys->i_header )
         {
             /* no need to restart stream, it was already one
@@ -358,7 +357,6 @@ static int Seek( access_t * p_access, int64_t i_pos )
 
     var_buffer_free( &buffer );
 
-
     while( !p_access->b_die )
     {
         if( mms_HeaderMediaRead( p_access, MMS_PACKET_CMD ) < 0 )
@@ -474,7 +472,6 @@ static int MMSOpen( access_t  *p_access, vlc_url_t *p_url, int  i_proto )
     int          i_streams;
     int          i_first;
 
-
     /* *** Open a TCP connection with server *** */
     msg_Dbg( p_access, "waiting for connection..." );
     p_sys->i_handle_tcp = net_ConnectTCP( p_access, p_url->psz_host, p_url->i_port );
@@ -781,7 +778,6 @@ static int MMSOpen( access_t  *p_access, vlc_url_t *p_url, int  i_proto )
     /* for now, select first audio and video stream */
     for( i = 1; i < 128; i++ )
     {
-
         if( p_sys->asfh.stream[i].i_cat != ASF_STREAM_UNKNOWN )
         {
             i_streams++;
@@ -841,7 +837,6 @@ static int MMSOpen( access_t  *p_access, vlc_url_t *p_url, int  i_proto )
         return VLC_EGENERIC;
     }
 
-
     var_buffer_free( &buffer );
 
     msg_Info( p_access, "connection successful" );
@@ -1137,16 +1132,23 @@ static int  mms_ParseCommand( access_t *p_access,
       ( p_sys->p_cmd[i_pos + 2] << 16 ) + \
       ( p_sys->p_cmd[i_pos + 3] << 24 ) )
 
-    access_sys_t        *p_sys = p_access->p_sys;
-    uint32_t    i_length;
-    uint32_t    i_id;
+    access_sys_t  *p_sys;
+    uint32_t i_length;
+    uint32_t i_id;
+
+    p_sys = p_access->p_sys;
+    if( !p_sys )
+        return -1;
 
     if( p_sys->p_cmd )
     {
         free( p_sys->p_cmd );
+        p_sys->p_cmd = NULL;
     }
     p_sys->i_cmd = i_data;
     p_sys->p_cmd = malloc( i_data );
+    if( !p_sys->p_cmd )
+        return -1;
     memcpy( p_sys->p_cmd, p_data, i_data );
 
     *pi_used = i_data; /* by default */
@@ -1207,13 +1209,11 @@ static int  mms_ParsePacket( access_t *p_access,
                              uint8_t *p_data, size_t i_data,
                              int *pi_used )
 {
-    access_sys_t        *p_sys = p_access->p_sys;
+    access_sys_t  *p_sys = p_access->p_sys;
     int i_packet_seq_num;
     size_t i_packet_length;
     uint32_t i_packet_id;
-
-    uint8_t  *p_packet;
-
+    uint8_t  *p_packet = NULL;
 
     *pi_used = i_data; /* default */
     if( i_data <= 8 )
@@ -1257,6 +1257,8 @@ static int  mms_ParsePacket( access_t *p_access,
 
     /* we now have a media or a header packet */
     p_packet = malloc( i_packet_length - 8 ); // don't bother with preheader
+    if( !p_packet )
+        return -1;
     memcpy( p_packet, p_data + 8, i_packet_length - 8 );
 
     if( i_packet_seq_num != p_sys->i_packet_seq_num )
@@ -1274,14 +1276,21 @@ static int  mms_ParsePacket( access_t *p_access,
     {
         if( p_sys->p_header )
         {
-            p_sys->p_header = realloc( p_sys->p_header,
-                                          p_sys->i_header + i_packet_length - 8 );
+            void *p_tmp;
+            p_tmp = realloc( p_sys->p_header,
+                             p_sys->i_header + i_packet_length - 8 );
+            if( !p_tmp )
+            {
+                free( p_packet );
+                return -1;
+            }
+
+            p_sys->p_header = p_tmp;
             memcpy( &p_sys->p_header[p_sys->i_header],
-                    p_packet,
-                    i_packet_length - 8 );
+                    p_packet, i_packet_length - 8 );
             p_sys->i_header += i_packet_length - 8;
-
             free( p_packet );
+            p_packet = NULL;
         }
         else
         {
@@ -1296,7 +1305,7 @@ static int  mms_ParsePacket( access_t *p_access,
     }
     else
     {
-        FREE( p_sys->p_media );
+        free( p_sys->p_media );
         p_sys->p_media = p_packet;
         p_sys->i_media = i_packet_length - 8;
         p_sys->i_media_used = 0;
@@ -1314,6 +1323,9 @@ static int mms_ReceivePacket( access_t *p_access )
     int i_packet_tcp_type;
     int i_packet_udp_type;
 
+    if( !p_sys )
+        return -1;
+
     for( ;; )
     {
         vlc_bool_t b_refill = VLC_TRUE;
@@ -1358,7 +1370,6 @@ static int mms_ReceivePacket( access_t *p_access )
                 i_packet_tcp_type =
                     mms_ParseCommand( p_access, p_sys->buffer_tcp,
                                       p_sys->i_buffer_tcp, &i_used );
-
             }
             else
             {
@@ -1460,10 +1471,14 @@ static int mms_ReceiveCommand( access_t *p_access )
 static int mms_CommandRead( access_t *p_access, int i_command1,
                             int i_command2 )
 {
-    access_sys_t *p_sys = p_access->p_sys;
+    access_sys_t *p_sys;
     int i_count;
     int i_status;
 
+    p_sys = p_access->p_sys;
+    if( !p_sys )
+        return VLC_EGENERIC;
+
     for( i_count = 0; i_count < MMS_RETRY_MAX; )
     {
         i_status = mms_ReceiveCommand( p_access );
@@ -1507,9 +1522,13 @@ static int mms_CommandRead( access_t *p_access, int i_command1,
 
 static int mms_HeaderMediaRead( access_t *p_access, int i_type )
 {
-    access_sys_t *p_sys = p_access->p_sys;
+    access_sys_t *p_sys;
     int          i_count;
 
+    p_sys = p_acces->p_sys;
+    if( !p_sys )
+        return -1;
+
     for( i_count = 0; i_count < MMS_RETRY_MAX; )
     {
         int i_status;
@@ -1560,4 +1579,3 @@ static int mms_HeaderMediaRead( access_t *p_access, int i_type )
     p_access->info.b_eof = VLC_TRUE;
     return -1;
 }
-




More information about the vlc-devel mailing list