[vlc-commits] lua: Ensure LuaGetState will always be called with a valid extension
Hugo Beauzée-Luyssen
git at videolan.org
Thu Mar 30 13:56:34 CEST 2017
vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Thu Mar 30 11:00:38 2017 +0200| [e382e0d71ee15f5efc6dc9c8dcc8edb23663a086] | committer: Hugo Beauzée-Luyssen
lua: Ensure LuaGetState will always be called with a valid extension
Otherwise the returned state wouldn't be stored in the extension, and
would eventually be leaked
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e382e0d71ee15f5efc6dc9c8dcc8edb23663a086
---
modules/lua/extension.c | 108 ++++++++++++++++++++++++------------------------
1 file changed, 53 insertions(+), 55 deletions(-)
diff --git a/modules/lua/extension.c b/modules/lua/extension.c
index e094799..a3616ad 100644
--- a/modules/lua/extension.c
+++ b/modules/lua/extension.c
@@ -540,6 +540,8 @@ static int Control( extensions_manager_t *p_mgr, int i_control, va_list args )
p_ext = ( extension_t* ) va_arg( args, extension_t* );
pppsz = ( char*** ) va_arg( args, char*** );
ppus = ( uint16_t** ) va_arg( args, uint16_t** );
+ if( p_ext == NULL )
+ return VLC_EGENERIC;
return GetMenuEntries( p_mgr, p_ext, pppsz, ppus );
case EXTENSION_TRIGGER_ONLY:
@@ -794,9 +796,8 @@ exit:
static lua_State* GetLuaState( extensions_manager_t *p_mgr,
extension_t *p_ext )
{
- lua_State *L = NULL;
- if( p_ext )
- L = p_ext->p_sys->L;
+ assert( p_ext != NULL );
+ lua_State *L = p_ext->p_sys->L;
if( !L )
{
@@ -815,69 +816,66 @@ static lua_State* GetLuaState( extensions_manager_t *p_mgr,
luaL_register_namespace( L, "vlc", p_reg );
luaopen_msg( L );
- if( p_ext )
+ /* Load more libraries */
+ luaopen_config( L );
+ luaopen_dialog( L, p_ext );
+ luaopen_input( L );
+ luaopen_msg( L );
+ if( vlclua_fd_init( L, &p_ext->p_sys->dtable ) )
{
- /* Load more libraries */
- luaopen_config( L );
- luaopen_dialog( L, p_ext );
- luaopen_input( L );
- luaopen_msg( L );
- if( vlclua_fd_init( L, &p_ext->p_sys->dtable ) )
- {
- lua_close( L );
- return NULL;
- }
- luaopen_object( L );
- luaopen_osd( L );
- luaopen_playlist( L );
- luaopen_sd_intf( L );
- luaopen_stream( L );
- luaopen_strings( L );
- luaopen_variables( L );
- luaopen_video( L );
- luaopen_vlm( L );
- luaopen_volume( L );
- luaopen_xml( L );
+ lua_close( L );
+ return NULL;
+ }
+ luaopen_object( L );
+ luaopen_osd( L );
+ luaopen_playlist( L );
+ luaopen_sd_intf( L );
+ luaopen_stream( L );
+ luaopen_strings( L );
+ luaopen_variables( L );
+ luaopen_video( L );
+ luaopen_vlm( L );
+ luaopen_volume( L );
+ luaopen_xml( L );
#if defined(_WIN32) && !VLC_WINSTORE_APP
- luaopen_win( L );
+ luaopen_win( L );
#endif
- /* Register extension specific functions */
- lua_getglobal( L, "vlc" );
- lua_pushcfunction( L, vlclua_extension_deactivate );
- lua_setfield( L, -2, "deactivate" );
- lua_pushcfunction( L, vlclua_extension_keep_alive );
- lua_setfield( L, -2, "keep_alive" );
+ /* Register extension specific functions */
+ lua_getglobal( L, "vlc" );
+ lua_pushcfunction( L, vlclua_extension_deactivate );
+ lua_setfield( L, -2, "deactivate" );
+ lua_pushcfunction( L, vlclua_extension_keep_alive );
+ lua_setfield( L, -2, "keep_alive" );
- /* Setup the module search path */
- if( !strncmp( p_ext->psz_name, "zip://", 6 ) )
- {
- /* Load all required modules manually */
- lua_register( L, "require", &vlclua_extension_require );
- }
- else
- {
- if( vlclua_add_modules_path( L, p_ext->psz_name ) )
- {
- msg_Warn( p_mgr, "Error while setting the module "
- "search path for %s", p_ext->psz_name );
- vlclua_fd_cleanup( &p_ext->p_sys->dtable );
- lua_close( L );
- return NULL;
- }
- }
- /* Load and run the script(s) */
- if( vlclua_dofile( VLC_OBJECT( p_mgr ), L, p_ext->psz_name ) )
+ /* Setup the module search path */
+ if( !strncmp( p_ext->psz_name, "zip://", 6 ) )
+ {
+ /* Load all required modules manually */
+ lua_register( L, "require", &vlclua_extension_require );
+ }
+ else
+ {
+ if( vlclua_add_modules_path( L, p_ext->psz_name ) )
{
- msg_Warn( p_mgr, "Error loading script %s: %s", p_ext->psz_name,
- lua_tostring( L, lua_gettop( L ) ) );
+ msg_Warn( p_mgr, "Error while setting the module "
+ "search path for %s", p_ext->psz_name );
vlclua_fd_cleanup( &p_ext->p_sys->dtable );
lua_close( L );
return NULL;
}
-
- p_ext->p_sys->L = L;
}
+ /* Load and run the script(s) */
+ if( vlclua_dofile( VLC_OBJECT( p_mgr ), L, p_ext->psz_name ) )
+ {
+ msg_Warn( p_mgr, "Error loading script %s: %s", p_ext->psz_name,
+ lua_tostring( L, lua_gettop( L ) ) );
+ vlclua_fd_cleanup( &p_ext->p_sys->dtable );
+ lua_close( L );
+ return NULL;
+ }
+
+ p_ext->p_sys->L = L;
}
return L;
More information about the vlc-commits
mailing list