[vlc-commits] libvlc: fix race on input_item_t.p_stats
Rémi Denis-Courmont
git at videolan.org
Mon Dec 11 21:02:25 CET 2017
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Dec 11 21:09:25 2017 +0200| [1fffacd6ea5df99f8d22111b13dfcfd3bcd49bca] | committer: Rémi Denis-Courmont
libvlc: fix race on input_item_t.p_stats
p_stats is written with the input item lock (by the input thread).
Thus the input item lock is necessary to read and dereference p_stats.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1fffacd6ea5df99f8d22111b13dfcfd3bcd49bca
---
lib/media.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/lib/media.c b/lib/media.c
index af246c6c7e..54875d6a0e 100644
--- a/lib/media.c
+++ b/lib/media.c
@@ -698,10 +698,20 @@ libvlc_media_subitems( libvlc_media_t * p_md )
int libvlc_media_get_stats( libvlc_media_t *p_md,
libvlc_media_stats_t *p_stats )
{
+ input_item_t *item = p_md->p_input_item;
+
if( !p_md->p_input_item )
return false;
+ vlc_mutex_lock( &item->lock );
+
input_stats_t *p_itm_stats = p_md->p_input_item->p_stats;
+ if( p_itm_stats == NULL )
+ {
+ vlc_mutex_unlock( &item->lock );
+ return false;
+ }
+
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;
@@ -724,6 +734,7 @@ int libvlc_media_get_stats( libvlc_media_t *p_md,
p_stats->i_sent_bytes = p_itm_stats->i_sent_bytes;
p_stats->f_send_bitrate = p_itm_stats->f_send_bitrate;
vlc_mutex_unlock( &p_itm_stats->lock );
+ vlc_mutex_unlock( &item->lock );
return true;
}
More information about the vlc-commits
mailing list