[vlc-devel] commit: mms/mmstu: fix a memleak and avoid to memcpy two times the same thing ( Rémi Duraffort )

git version control git at videolan.org
Mon Dec 15 23:17:14 CET 2008


vlc | branch: master | Rémi Duraffort <ivoire at videolan.org> | Mon Dec 15 22:48:47 2008 +0100| [834d3847f87db04f089f93ffe76d4ee711822484] | committer: Rémi Duraffort 

mms/mmstu: fix a memleak and avoid to memcpy two times the same thing
(but yes duplicate 2 lines of code).

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

 modules/access/mms/mmstu.c |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/modules/access/mms/mmstu.c b/modules/access/mms/mmstu.c
index b1229e9..915223d 100644
--- a/modules/access/mms/mmstu.c
+++ b/modules/access/mms/mmstu.c
@@ -1256,9 +1256,6 @@ static int  mms_ParsePacket( access_t *p_access,
     size_t i_packet_length;
     uint32_t i_packet_id;
 
-    uint8_t  *p_packet;
-
-
     *pi_used = i_data; /* default */
     if( i_data <= 8 )
     {
@@ -1300,9 +1297,6 @@ 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
-    memcpy( p_packet, p_data + 8, i_packet_length - 8 );
-
     if( i_packet_seq_num != p_sys->i_packet_seq_num )
     {
 #if 0
@@ -1322,14 +1316,14 @@ static int  mms_ParsePacket( access_t *p_access,
             p_sys->p_header = realloc( p_sys->p_header,
                                           p_sys->i_header + i_packet_length - 8 );
             memcpy( &p_sys->p_header[p_sys->i_header],
-                    p_packet,
-                    i_packet_length - 8 );
+                    p_data + 8, i_packet_length - 8 );
             p_sys->i_header += i_packet_length - 8;
 
-            free( p_packet );
         }
         else
         {
+            uint8_t* p_packet = malloc( 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;
         }
@@ -1341,6 +1335,8 @@ static int  mms_ParsePacket( access_t *p_access,
     }
     else
     {
+        uint8_t* p_packet = malloc( i_packet_length - 8 ); // don't bother with preheader
+        memcpy( p_packet, p_data + 8, i_packet_length - 8 );
         FREENULL( p_sys->p_media );
         p_sys->p_media = p_packet;
         p_sys->i_media = i_packet_length - 8;




More information about the vlc-devel mailing list