[vlc-commits] lua: fix race on input_item_t.p_stats

Rémi Denis-Courmont git at videolan.org
Mon Dec 11 21:02:23 CET 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Dec 11 21:09:25 2017 +0200| [7bac48bd52847fe1dc5cf25ee8068888cd38fc82] | committer: Rémi Denis-Courmont

lua: 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=7bac48bd52847fe1dc5cf25ee8068888cd38fc82
---

 modules/lua/libs/input.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/modules/lua/libs/input.c b/modules/lua/libs/input.c
index 229f52b6e5..7490cd5d26 100644
--- a/modules/lua/libs/input.c
+++ b/modules/lua/libs/input.c
@@ -191,7 +191,12 @@ static int vlclua_input_item_stats( lua_State *L )
 {
     input_item_t *p_item = vlclua_input_item_get_internal( L );
     lua_newtable( L );
-    if( p_item )
+    if( p_item == NULL )
+        return 1;
+
+    vlc_mutex_lock( &p_item->lock );
+    input_stats_t *p_stats = p_item->p_stats;
+    if( p_stats != NULL )
     {
         vlc_mutex_lock( &p_item->p_stats->lock );
 #define STATS_INT( n ) lua_pushinteger( L, p_item->p_stats->i_ ## n ); \
@@ -221,6 +226,7 @@ static int vlclua_input_item_stats( lua_State *L )
 #undef STATS_FLOAT
         vlc_mutex_unlock( &p_item->p_stats->lock );
     }
+    vlc_mutex_unlock( &p_item->lock );
     return 1;
 }
 



More information about the vlc-commits mailing list