]> git.sesse.net Git - vlc/commitdiff
Smooth Streaming: fix some memory leaks
authorFrédéric Yhuel <yhuelf@gmail.com>
Wed, 10 Oct 2012 16:54:57 +0000 (18:54 +0200)
committerJean-Baptiste Kempf <jb@videolan.org>
Fri, 12 Oct 2012 09:21:34 +0000 (11:21 +0200)
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/stream_filter/smooth/smooth.c
modules/stream_filter/smooth/smooth.h
modules/stream_filter/smooth/utils.c

index 3e7d9a5333f48b92ea474ef6c3d21b383fe22cd9..9a4ad2090e9752f9341e4b27ad4ceb8c26f84b35 100644 (file)
@@ -146,9 +146,7 @@ static int parse_Manifest( stream_t *s )
     }
 
     const char *node;
-    char *stream_name = NULL;
     uint8_t *WaveFormatEx;
-    int stream_type = UNKNOWN_ES;
     sms_stream_t *sms = NULL;
     quality_level_t *ql = NULL;
     int64_t start_time = 0, duration = 0;
@@ -192,15 +190,15 @@ static int parse_Manifest( stream_t *s )
                         if( !strcmp( name, "Type" ) )
                         {
                             if( !strcmp( value, "video" ) )
-                                stream_type = VIDEO_ES;
+                                sms->type = VIDEO_ES;
                             else if( !strcmp( value, "audio" ) )
-                                stream_type = AUDIO_ES;
+                                sms->type = AUDIO_ES;
                             else if( !strcmp( value, "text" ) )
-                                stream_type = SPU_ES;
+                                sms->type = SPU_ES;
                         }
 
                         if( !strcmp( name, "Name" ) )
-                            stream_name = strdup( value );
+                            sms->name = strdup( value );
                         if( !strcmp( name, "TimeScale" ) )
                             sms->timescale = strtoull( value, NULL, 10 );
                         if( !strcmp( name, "FourCC" ) )
@@ -222,18 +220,16 @@ static int parse_Manifest( stream_t *s )
 
                     if( sms && !sms->timescale )
                         sms->timescale = TIMESCALE;
-                    if( !stream_name )
+                    if( !sms->name )
                     {
-                        if( stream_type == VIDEO_ES )
-                            stream_name = strdup( "video" );
-                        else if( stream_type == AUDIO_ES )
-                            stream_name = strdup( "audio" );
-                        else if( stream_type == SPU_ES )
-                            stream_name = strdup( "text" );
+                        if( sms->type == VIDEO_ES )
+                            sms->name = strdup( "video" );
+                        else if( sms->type == AUDIO_ES )
+                            sms->name = strdup( "audio" );
+                        else if( sms->type == SPU_ES )
+                            sms->name = strdup( "text" );
                     }
 
-                    sms->name = stream_name;
-                    sms->type = stream_type;
                     vlc_array_append( p_sys->sms_streams, sms );
                 }
 
@@ -346,8 +342,6 @@ static int parse_Manifest( stream_t *s )
                 if( strcmp( node, "StreamIndex" ) )
                     break;
 
-                stream_name = NULL;
-                stream_type = UNKNOWN_ES;
                 computed_start_time = 0;
                 computed_duration = 0;
                 loop_count = 0;
@@ -502,7 +496,9 @@ static void Close( vlc_object_t *p_this )
             sms_Free( sms );
     }
 
+    sms_queue_free( p_sys->bws );
     vlc_array_destroy( p_sys->sms_streams );
+    vlc_array_destroy( p_sys->selected_st );
     vlc_array_destroy( p_sys->download.chunks );
 
     free( p_sys->base_url );
index dbc32edb9d45252a8d863f0ef516b8d97709db82..965fa0ebd88181fdeea27b2137aea178fdc35d52 100644 (file)
@@ -165,6 +165,7 @@ struct stream_sys_t
 #define NO_MORE_CHUNKS ( !p_sys->b_live && \
     no_more_chunks( p_sys->download.ck_index, p_sys->selected_st ) )
 
+void sms_queue_free( sms_queue_t* );
 sms_queue_t *sms_queue_init( const int );
 int sms_queue_put( sms_queue_t *, const uint64_t );
 uint64_t sms_queue_avg( sms_queue_t *);
index be27c039e13dc341fe71e9a026cb8f5a99111938..d02d63c433dbe9e04f9560908c1466b2d2d08e5c 100644 (file)
@@ -136,6 +136,8 @@ void sms_Free( sms_stream_t *sms )
         vlc_array_destroy( sms->chunks );
     }
 
+    free( sms->name );
+    free( sms->url_template );
     free( sms );
     sms = NULL;
 }
@@ -162,18 +164,37 @@ sms_queue_t *sms_queue_init( const int length )
     return ret;
 }
 
+void sms_queue_free( sms_queue_t* queue )
+{
+    item_t *item = queue->first, *next = NULL;
+    while( item )
+    {
+        next = item->next;
+        FREENULL( item );
+        item = next;
+    }
+    FREENULL( queue );
+}
+
 int sms_queue_put( sms_queue_t *queue, const uint64_t value )
 {
-    item_t *last = queue->first;
-    int i = 0;
-    for( i = 0; i < queue->length - 1; i++ )
+    /* Remove the last (and oldest) item */
+    item_t *item, *prev;
+    int count = 0;
+    for( item = queue->first; item != NULL; item = item->next )
     {
-        if( last )
-            last = last->next;
+        count++;
+        if( count == queue->length )
+        {
+            FREENULL( item );
+            if( prev ) prev->next = NULL;
+            break;
+        }
+        else
+            prev = item;
     }
-    if( i == queue->length - 1 )
-        FREENULL( last );
 
+    /* Now insert the new item */
     item_t *new = malloc( sizeof( item_t ) );
     if( unlikely( !new ) )
         return VLC_ENOMEM;