mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:18:37 +00:00
leonida-lua: keep a mod's state only once it has loaded
A mod that fails to load no longer holds its state (and up to 128 MiB) until the next reload; the handles it left behind go when the failure switches it off. (Review of #3179.)
This commit is contained in:
@ -266,7 +266,6 @@ impl Runtime {
|
||||
let code = std::fs::read(&path).map_err(|e| format!("cannot read {script}: {e}"))?;
|
||||
let lua =
|
||||
sandbox::new_lua(&self.guard).map_err(|e| format!("cannot set the mod up: {e}"))?;
|
||||
self.states.push(lua.clone());
|
||||
let env = api::build_env(&lua, &self.guard, &self.shared, idx, folder)
|
||||
.map_err(|e| format!("cannot set the mod up: {e}"))?;
|
||||
let function = lua
|
||||
@ -283,7 +282,11 @@ impl Runtime {
|
||||
.into_function()
|
||||
.map_err(|e| e.to_string())?;
|
||||
self.guard.start(self.config.budget.load);
|
||||
function.call::<()>(()).map_err(|e| e.to_string())
|
||||
function.call::<()>(()).map_err(|e| e.to_string())?;
|
||||
// Kept only for a mod that loaded: a failed one's state (and its
|
||||
// memory) goes now, and the handles it left behind go with `disable`.
|
||||
self.states.push(lua);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Calls `function` for mod `idx` with `args`, within the call budget; an
|
||||
|
||||
Reference in New Issue
Block a user