[vlc-devel] [PATCH 02/19] lib/media_discoverer: libvlc_media_discoverer_release: simplify
Filip Roséen
filip at atch.se
Thu May 18 12:19:08 CEST 2017
The email in which this is a reply to inaccurately states "01/19" in
the subject, which was not at all wanted.
The patch should simply be on its own.
Sorry about the inconvenience,\
Filip
On 2017-05-18 12:16, Filip Roséen wrote:
> 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.
> ---
> 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 );
>
> --
> 2.12.2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20170518/cec78f6a/attachment.html>
More information about the vlc-devel
mailing list