From 2f2f697c0a6c3bc0c8ff9322a1a0eb78ef55aa98 Mon Sep 17 00:00:00 2001 From: eipastel Date: Wed, 2 Dec 2026 15:28:39 -0300 Subject: [PATCH] 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.) --- d3d12/crates/leonida-lua/src/runtime.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/d3d12/crates/leonida-lua/src/runtime.rs b/d3d12/crates/leonida-lua/src/runtime.rs index b9e911dab..c56aae714 100644 --- a/d3d12/crates/leonida-lua/src/runtime.rs +++ b/d3d12/crates/leonida-lua/src/runtime.rs @@ -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