[vlc-commits] access: mmstu: drop xrealloc and simplify

Francois Cartegnie git at videolan.org
Mon Dec 28 23:35:53 CET 2015


vlc/vlc-2.2 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Dec 28 14:17:14 2015 +0100| [609b18afca52acf9a1e5e7b09ac3c1f4b440184b] | committer: Jean-Baptiste Kempf

access: mmstu: drop xrealloc and simplify

(cherry picked from commit de4b5430990bd7d2b48b33cd88d1747c5f943131)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=609b18afca52acf9a1e5e7b09ac3c1f4b440184b
---

 modules/access/mms/mmstu.c |   24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/modules/access/mms/mmstu.c b/modules/access/mms/mmstu.c
index 2c4e40e..7723af4 100644
--- a/modules/access/mms/mmstu.c
+++ b/modules/access/mms/mmstu.c
@@ -960,6 +960,7 @@ static void MMSClose( access_t  *p_access )
     FREENULL( p_sys->p_cmd );
     FREENULL( p_sys->p_media );
     FREENULL( p_sys->p_header );
+    p_sys->i_header = 0;
 
     FREENULL( p_sys->psz_server_version );
     FREENULL( p_sys->psz_tool_version );
@@ -1290,22 +1291,15 @@ static int  mms_ParsePacket( access_t *p_access,
 
     if( i_packet_id == p_sys->i_header_packet_id_type )
     {
-        if( p_sys->p_header )
-        {
-            p_sys->p_header = xrealloc( p_sys->p_header,
-                                      p_sys->i_header + i_packet_length - 8 );
-            memcpy( &p_sys->p_header[p_sys->i_header],
-                    p_data + 8, i_packet_length - 8 );
-            p_sys->i_header += i_packet_length - 8;
+        uint8_t *p_reaced = realloc( p_sys->p_header,
+                                     p_sys->i_header + i_packet_length - 8 );
+        if( !p_reaced )
+            return VLC_ENOMEM;
+
+        memcpy( &p_reaced[p_sys->i_header], p_data + 8, i_packet_length - 8 );
+        p_sys->p_header = p_reaced;
+        p_sys->i_header += i_packet_length - 8;
 
-        }
-        else
-        {
-            uint8_t* p_packet = xmalloc( i_packet_length - 8 ); // don't bother with preheader
-            memcpy( p_packet, p_data + 8, i_packet_length - 8 );
-            p_sys->p_header = p_packet;
-            p_sys->i_header = i_packet_length - 8;
-        }
 /*        msg_Dbg( p_access,
                  "receive header packet (%d bytes)",
                  i_packet_length - 8 ); */



More information about the vlc-commits mailing list