From 4e67aa72c0e24c5b42afc0b625f45512476288a7 Mon Sep 17 00:00:00 2001 From: meehl <12648828+meehl@users.noreply.github.com> Date: Thu, 27 Aug 2026 15:31:03 +0200 Subject: [PATCH] Acquire context reference after argument validation in image_handle_load luaL_error can perform a long jump and never return. `drop` might not get called on the AppDataRef, leaving it permanently borrowed. --- src/pob/api/image_handle.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pob/api/image_handle.rs b/src/pob/api/image_handle.rs index 5a4f8ac..f1046a9 100644 --- a/src/pob/api/image_handle.rs +++ b/src/pob/api/image_handle.rs @@ -177,9 +177,6 @@ unsafe extern "C-unwind" fn image_handle_unload(state: *mut ffi::lua_State) -> c unsafe extern "C-unwind" fn image_handle_load(state: *mut ffi::lua_State) -> c_int { let handle = unsafe { get_image_handle(state, 1) }; - let lua = unsafe { Lua::get_or_init_from_ptr(state) }; - let ctx = lua.app_data_ref::().unwrap(); - // Path let path_ptr = unsafe { ffi::luaL_checklstring(state, 2, ptr::null_mut()) }; @@ -242,6 +239,9 @@ unsafe extern "C-unwind" fn image_handle_load(state: *mut ffi::lua_State) -> c_i // Load / update let handle = unsafe { &mut *handle }; + let lua = unsafe { Lua::get_or_init_from_ptr(state) }; + let ctx = lua.app_data_ref::().unwrap(); + match &mut handle.texture { Some(texture_handle) => { // Keep the existing TextureHandle and update underlying texture