[vlc-commits] Smooth Streaming: fix a memory leak

Frédéric Yhuel git at videolan.org
Fri Oct 12 11:22:37 CEST 2012


vlc | branch: master | Frédéric Yhuel <yhuelf at gmail.com> | Wed Oct 10 18:54:59 2012 +0200| [1ef0c797aa9b2ba3621bf4d01e4d790545d39c83] | committer: Jean-Baptiste Kempf

Smooth Streaming: fix a memory leak

initialization chunks were not freed on Close()

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/stream_filter/smooth/downloader.c |    3 +++
 modules/stream_filter/smooth/smooth.c     |   13 +++++++++++--
 modules/stream_filter/smooth/smooth.h     |    1 +
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/modules/stream_filter/smooth/downloader.c b/modules/stream_filter/smooth/downloader.c
index 26cca95..3173849 100644
--- a/modules/stream_filter/smooth/downloader.c
+++ b/modules/stream_filter/smooth/downloader.c
@@ -514,6 +514,7 @@ static int Download( stream_t *s, sms_stream_t *sms )
 
         vlc_mutex_lock( &p_sys->download.lock_wait );
         vlc_array_append( p_sys->download.chunks, new_init_ck );
+        vlc_array_append( p_sys->init_chunks, new_init_ck );
         vlc_mutex_unlock( &p_sys->download.lock_wait );
     }
     return VLC_SUCCESS;
@@ -578,6 +579,7 @@ void* sms_Thread( void *p_this )
 
     vlc_mutex_lock( &p_sys->download.lock_wait );
     vlc_array_append( p_sys->download.chunks, init_ck );
+    vlc_array_append( p_sys->init_chunks, init_ck );
     vlc_mutex_unlock( &p_sys->download.lock_wait );
 
     p_sys->download.next_chunk_offset = init_ck->size;
@@ -664,6 +666,7 @@ void* sms_Thread( void *p_this )
             p_sys->download.next_chunk_offset += new_init_ck->size;
 
             vlc_array_append( p_sys->download.chunks, new_init_ck );
+            vlc_array_append( p_sys->init_chunks, new_init_ck );
             p_sys->b_tseek = false;
         }
         vlc_mutex_unlock( &p_sys->download.lock_wait );
diff --git a/modules/stream_filter/smooth/smooth.c b/modules/stream_filter/smooth/smooth.c
index 7293ab1..15bc5f7 100644
--- a/modules/stream_filter/smooth/smooth.c
+++ b/modules/stream_filter/smooth/smooth.c
@@ -403,8 +403,9 @@ static int Open( vlc_object_t *p_this )
     p_sys->sms_streams = vlc_array_new();
     p_sys->selected_st = vlc_array_new();
     p_sys->download.chunks = vlc_array_new();
+    p_sys->init_chunks = vlc_array_new();
     if( unlikely( !p_sys->sms_streams || !p_sys->download.chunks ||
-                  !p_sys->selected_st ) )
+                  !p_sys->selected_st || !p_sys->init_chunks ) )
     {
         free( p_sys );
         return VLC_ENOMEM;
@@ -492,14 +493,22 @@ static void Close( vlc_object_t *p_this )
     for( int i = 0; i < vlc_array_count( p_sys->sms_streams ); i++ )
     {
         sms = vlc_array_item_at_index( p_sys->sms_streams, i );
-        if( sms)
+        if( sms )
             sms_Free( sms );
     }
+    /* Free downloaded chunks */
+    chunk_t *chunk;
+    for( int i = 0; i < vlc_array_count( p_sys->init_chunks ); i++ )
+    {
+        chunk = vlc_array_item_at_index( p_sys->init_chunks, i );
+        chunk_Free( chunk );
+    }
 
     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 );
+    vlc_array_destroy( p_sys->init_chunks );
 
     free( p_sys->base_url );
     free( p_sys );
diff --git a/modules/stream_filter/smooth/smooth.h b/modules/stream_filter/smooth/smooth.h
index c121973..a800dd7 100644
--- a/modules/stream_filter/smooth/smooth.h
+++ b/modules/stream_filter/smooth/smooth.h
@@ -92,6 +92,7 @@ struct stream_sys_t
 
     vlc_array_t  *sms_streams; /* available streams */
     vlc_array_t  *selected_st; /* selected streams */
+    vlc_array_t  *init_chunks;
     unsigned     i_tracks;     /* Total number of tracks in the Manifest */
     sms_queue_t  *bws;         /* Measured bandwidths of the N last chunks */
     uint64_t     vod_duration; /* total duration of the VOD media */



More information about the vlc-commits mailing list