Commit a1963944 authored by Filip Roséen's avatar Filip Roséen Committed by 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's avatarRémi Denis-Courmont <remi@remlab.net>
parent d2e4278b
...@@ -243,6 +243,13 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst, ...@@ -243,6 +243,13 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
/************************************************************************** /**************************************************************************
* release (Public) * release (Public)
**************************************************************************/ **************************************************************************/
static void
MediaListDictValueRelease( void* mlist, void* obj )
{
libvlc_media_list_release( mlist );
(void)obj;
}
void void
libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis ) libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis )
{ {
...@@ -251,17 +258,9 @@ 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 ); libvlc_media_list_release( p_mdis->p_mlist );
/* Free catname_to_submedialist and all the mlist */ vlc_dictionary_clear( &p_mdis->catname_to_submedialist,
char ** all_keys = vlc_dictionary_all_keys( &p_mdis->catname_to_submedialist ); MediaListDictValueRelease, NULL );
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, NULL, NULL );
libvlc_event_manager_destroy( &p_mdis->event_manager ); libvlc_event_manager_destroy( &p_mdis->event_manager );
libvlc_release( p_mdis->p_libvlc_instance ); libvlc_release( p_mdis->p_libvlc_instance );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment