[vlc-commits] lua: fix race on input_item_t.p_stats
Rémi Denis-Courmont
git at videolan.org
Mon Dec 11 21:06:59 CET 2017
vlc/vlc-3.0 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Dec 11 21:09:25 2017 +0200| [40ac6bfeb5eadbc1ac94376ba629c8c843949704] | 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.
(cherry picked from commit 7bac48bd52847fe1dc5cf25ee8068888cd38fc82)
> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=40ac6bfeb5eadbc1ac94376ba629c8c843949704
---
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