[vlc-devel] commit: (live555) memleak fixing (Jean-Paul Saman )

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


vlc | branch: 0.8.6-bugfix | Jean-Paul Saman <jpsaman at videolan.org> | Sun Nov 23 15:20:16 2008 +0100| [076fa251c31acbbfd91ac114b80c851e6012f42a] | committer: Jean-Paul Saman 

(live555) memleak fixing

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

 modules/demux/live555.cpp |   64 ++++++++++++++++++++++++++++----------------
 1 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/modules/demux/live555.cpp b/modules/demux/live555.cpp
index 89ff69b..bb6414b 100644
--- a/modules/demux/live555.cpp
+++ b/modules/demux/live555.cpp
@@ -2,7 +2,7 @@
  * live555.cpp : LIVE555 Streaming Media support.
  *****************************************************************************
  * Copyright (C) 2003-2006 the VideoLAN team
- * $Id$
+ * $Id: 89ff69b034fecb0eb8daf975bd67ff4617a21f24 $
  *
  * Authors: Laurent Aimar <fenrir at via.ecp.fr>
  *
@@ -374,20 +374,20 @@ static int  Open ( vlc_object_t *p_this )
         goto error;
     }
 
+    i_return = Play( p_demux );
+    if( i_return != VLC_SUCCESS )
+        goto error;
+
     /* Retrieve the duration if possible */
     p_sys->i_length = (int64_t)( p_sys->ms->playEndTime() * 1000000.0 );
     if( p_sys->i_length < 0 )
         p_sys->i_length = -1;
 
-    i_return = Play( p_demux );
-    if( i_return != VLC_SUCCESS )
-        goto error;
-
     /* Create all es struct */
     iter = new MediaSubsessionIterator( *p_sys->ms );
     while( ( sub = iter->next() ) != NULL )
     {
-        live_track_t *tk;
+        live_track_t *tk = NULL;
 
         if( p_demux->b_die || p_demux->b_error )
         {
@@ -399,7 +399,7 @@ static int  Open ( vlc_object_t *p_this )
         if( sub->readSource() == NULL ) continue;
 
         tk = (live_track_t*)malloc( sizeof( live_track_t ) );
-	if( !tk ) 
+        if( !tk )
         {
             delete iter;
             goto error;
@@ -418,6 +418,7 @@ static int  Open ( vlc_object_t *p_this )
 
         if( !tk->p_buffer )
         {
+            free( tk );
             delete iter;
             goto error;
         }
@@ -491,9 +492,12 @@ static int  Open ( vlc_object_t *p_this )
                 if( ( p_extra = parseStreamMuxConfigStr( sub->fmtp_config(),
                                                          i_extra ) ) )
                 {
-                    tk->fmt.i_extra = i_extra;
-                    tk->fmt.p_extra = malloc( i_extra );
-                    memcpy( tk->fmt.p_extra, p_extra, i_extra );
+                    tk->fmt.p_extra = malloc( tk->fmt.i_extra );
+                    if( tk->fmt.p_extra )
+                    {
+                        tk->fmt.i_extra = i_extra;
+                        memcpy( tk->fmt.p_extra, p_extra, i_extra );
+                    }
                     delete[] p_extra;
                 }
 
@@ -513,9 +517,12 @@ static int  Open ( vlc_object_t *p_this )
                 if( ( p_extra = parseGeneralConfigStr( sub->fmtp_config(),
                                                        i_extra ) ) )
                 {
-                    tk->fmt.i_extra = i_extra;
-                    tk->fmt.p_extra = malloc( i_extra );
-                    memcpy( tk->fmt.p_extra, p_extra, i_extra );
+                    tk->fmt.p_extra = malloc( tk->fmt.i_extra );
+                    if( tk->fmt.p_extra )
+                    {
+                        tk->fmt.i_extra = i_extra;
+                        memcpy( tk->fmt.p_extra, p_extra, i_extra );
+                    }
                     delete[] p_extra;
                 }
             }
@@ -558,10 +565,12 @@ static int  Open ( vlc_object_t *p_this )
                 if((p_extra=parseH264ConfigStr( sub->fmtp_spropparametersets(),
                                                 i_extra ) ) )
                 {
-                    tk->fmt.i_extra = i_extra;
-                    tk->fmt.p_extra = malloc( i_extra );
-                    memcpy( tk->fmt.p_extra, p_extra, i_extra );
-
+                    tk->fmt.p_extra = malloc( tk->fmt.i_extra );
+                    if( tk->fmt.p_extra )
+                    {
+                        tk->fmt.i_extra = i_extra;
+                        memcpy( tk->fmt.p_extra, p_extra, i_extra );
+                    }
                     delete[] p_extra;
                 }
 #endif
@@ -580,9 +589,12 @@ static int  Open ( vlc_object_t *p_this )
                 if( ( p_extra = parseGeneralConfigStr( sub->fmtp_config(),
                                                        i_extra ) ) )
                 {
-                    tk->fmt.i_extra = i_extra;
-                    tk->fmt.p_extra = malloc( i_extra );
-                    memcpy( tk->fmt.p_extra, p_extra, i_extra );
+                    tk->fmt.p_extra = malloc( tk->fmt.i_extra );
+                    if( tk->fmt.p_extra )
+                    {
+                        tk->fmt.i_extra = i_extra;
+                        memcpy( tk->fmt.p_extra, p_extra, i_extra );
+                    }
                     delete[] p_extra;
                 }
             }
@@ -627,17 +639,24 @@ static int  Open ( vlc_object_t *p_this )
 
         if( tk->p_es || tk->b_quicktime || tk->b_muxed || tk->b_asf )
         {
+            live_track_t **pp_tmp;
+
             tk->readSource = sub->readSource();
             tk->rtpSource  = sub->rtpSource();
 
             /* Append */
-            p_sys->track = (live_track_t**)realloc( p_sys->track, sizeof( live_track_t ) * ( p_sys->i_track + 1 ) );
-            p_sys->track[p_sys->i_track++] = tk;
+            pp_tmp = (live_track_t**)realloc( p_sys->track, sizeof( live_track_t ) * ( p_sys->i_track + 1 ) );
+            if( pp_tmp )
+            {
+                p_sys->track = pp_tmp;
+                p_sys->track[p_sys->i_track++] = tk;
+            }
         }
         else
         {
             /* BUG ??? */
             msg_Err( p_demux, "unusable RTSP track. this should not happen" );
+            free( tk->p_buffer );
             free( tk );
         }
     }
@@ -673,7 +692,6 @@ error:
     if( p_sys->psz_path ) free( p_sys->psz_path );
 
     vlc_UrlClean( &p_sys->url );
-
     free( p_sys );
     return VLC_EGENERIC;
 }




More information about the vlc-devel mailing list