Commit e382e0d7 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

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
parent b56c9993
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment