[vlc-commits] lib/media_discoverer: libvlc_media_discoverer_release: simplify

Filip Roséen git at videolan.org
Thu May 18 18:08:38 CEST 2017


vlc | branch: master | Filip Roséen <filip at atch.se> | Thu May 18 12:16:56 2017 +0200| [a1963944d4e4d14123823e63aeda512b738e3982] | committer: Rémi Denis-Courmont

lib/media_discoverer: libvlc_media_discoverer_release: simplify

Instead of getting all the dictionary keys, and iterating over them to
get the associated values, only to free/release the associated data;
use vlc_dictionary_clear together with a callback to handle the work
for us.

These changes also fixes a potential null-pointer dereference if the
previous usage of vlc_dictionary_all_keys failed.

Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>

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

 lib/media_discoverer.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/lib/media_discoverer.c b/lib/media_discoverer.c
index 4f1f215062..367d7ea8e8 100644
--- a/lib/media_discoverer.c
+++ b/lib/media_discoverer.c
@@ -243,6 +243,13 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
 /**************************************************************************
  * release (Public)
  **************************************************************************/
+static void
+MediaListDictValueRelease( void* mlist, void* obj )
+{
+    libvlc_media_list_release( mlist );
+    (void)obj;
+}
+
 void
 libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis )
 {
@@ -251,17 +258,9 @@ libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis )
 
     libvlc_media_list_release( p_mdis->p_mlist );
 
-    /* Free catname_to_submedialist and all the mlist */
-    char ** all_keys = vlc_dictionary_all_keys( &p_mdis->catname_to_submedialist );
-    for( int i = 0; all_keys[i]; i++ )
-    {
-        libvlc_media_list_t * p_catmlist = vlc_dictionary_value_for_key( &p_mdis->catname_to_submedialist, all_keys[i] );
-        libvlc_media_list_release( p_catmlist );
-        free( all_keys[i] );
-    }
-    free( all_keys );
+    vlc_dictionary_clear( &p_mdis->catname_to_submedialist,
+        MediaListDictValueRelease, NULL );
 
-    vlc_dictionary_clear( &p_mdis->catname_to_submedialist, NULL, NULL );
     libvlc_event_manager_destroy( &p_mdis->event_manager );
     libvlc_release( p_mdis->p_libvlc_instance );
 



More information about the vlc-commits mailing list