[vlc-devel] [PATCH] Fixed crash when getting statistics on uninitalized media (with thread-safe fix)

Jeremy Vignelles jeremy.vignelles at dev3i.fr
Thu Oct 19 14:00:51 CEST 2017


This isn't a good protection as I thought first : p_input_item or p_stats can be freed before being really used.

I was thinking like a .net developper, with garbage collection in mind, sorry for my mistakes.

If I understand correctly, we need some vlc_mutex_lock inside, but I'm unsure on what to lock.
Do we need another lock for that? Is the current code considered as thread-safe?

Regards,
Jérémy VIGNELLES

> Le 19 octobre 2017 à 11:53, Jérémy VIGNELLES <jeremy.vignelles at dev3i.fr> a écrit :
> 
> ---
>  lib/media.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/media.c b/lib/media.c
> index 8da5a130e2..27fd24f617 100644
> --- a/lib/media.c
> +++ b/lib/media.c
> @@ -698,10 +698,14 @@ libvlc_media_subitems( libvlc_media_t * p_md )
>  int libvlc_media_get_stats( libvlc_media_t *p_md,
>  libvlc_media_stats_t *p_stats )
>  {
> 
> *   if( !p_md->p_input_item )
> 
> *   input_item_t *p_input_item = p_md->p_input_item;
> *   if( !p_input_item )
> *   return false;
> +
> *   input_stats_t *p_itm_stats = p_input_item->p_stats;
> *   if( !p_itm_stats )
>  return false;
> 
> *   input_stats_t *p_itm_stats = p_md->p_input_item->p_stats;
> vlc_mutex_lock( &p_itm_stats->lock );
> p_stats->i_read_bytes = p_itm_stats->i_read_bytes;
> p_stats->f_input_bitrate = p_itm_stats->f_input_bitrate;
> --
> 2.11.0


More information about the vlc-devel mailing list