]> git.sesse.net Git - vlc/commitdiff
libvlc: media: fix leak if it has subitems
authorThomas Guillem <thomas@gllm.fr>
Tue, 20 Jan 2015 09:46:29 +0000 (10:46 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Tue, 20 Jan 2015 10:20:27 +0000 (11:20 +0100)
Don't call libvlc_media_list_set_media from media since it causes
p_md->p_subitems to retain p_md while p_md is already retaining
p_md->p_subitems, therefore these 2 objects won't be releasable.

Add a new internal variable: p_internal_md that is set from media without
retaining it.

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
lib/media.c
lib/media_list.c
lib/media_list_internal.h

index c73c5b1859bed0fd8ed7a9bc9467a0e05252f305..b8b7620c1b5d23fb8933ba6075f6b06103b2094d 100644 (file)
@@ -115,7 +115,7 @@ static libvlc_media_list_t *media_get_subitems( libvlc_media_t * p_md )
         if( p_md->p_subitems != NULL )
         {
             p_md->p_subitems->b_read_only = true;
-            libvlc_media_list_set_media( p_md->p_subitems, p_md );
+            p_md->p_subitems->p_internal_md = p_md;
         }
     }
     p_subitems = p_md->p_subitems;
index dff4edb5ecd826cc2b25c8520426bb27b2da1461..62f0c31d210ac56ea596b581bf80257d5e8ac2e9 100644 (file)
@@ -184,6 +184,7 @@ libvlc_media_list_new( libvlc_instance_t * p_inst )
     assert( p_mlist->items.i_count == 0 );
     p_mlist->i_refcount = 1;
     p_mlist->p_md = NULL;
+    p_mlist->p_internal_md = NULL;
 
     return p_mlist;
 }
@@ -285,6 +286,11 @@ void libvlc_media_list_set_media( libvlc_media_list_t * p_mlist,
 
 {
     vlc_mutex_lock( &p_mlist->object_lock );
+    if( p_mlist->p_internal_md )
+    {
+        vlc_mutex_unlock( &p_mlist->object_lock );
+        return;
+    }
     libvlc_media_release( p_mlist->p_md );
     libvlc_media_retain( p_md );
     p_mlist->p_md = p_md;
@@ -306,7 +312,7 @@ libvlc_media_list_media( libvlc_media_list_t * p_mlist )
     libvlc_media_t *p_md;
 
     vlc_mutex_lock( &p_mlist->object_lock );
-    p_md = p_mlist->p_md;
+    p_md = p_mlist->p_internal_md ? p_mlist->p_internal_md : p_mlist->p_md;
     if( p_md )
         libvlc_media_retain( p_md );
     vlc_mutex_unlock( &p_mlist->object_lock );
index 9c2412b3557c94c3ae0cbca1107ea9bc9200fb5c..47d2fbf807577953c43610ede3c4762a65cee74d 100644 (file)
@@ -44,6 +44,7 @@ struct libvlc_media_list_t
     vlc_mutex_t                 refcount_lock;
     libvlc_media_t * p_md; /* The media from which the
                                        * mlist comes, if any. */
+    libvlc_media_t * p_internal_md; /* media set from media.c */
     vlc_array_t                items;
 
     /* This indicates if this media list is read-only