@@ -16,6 +16,10 @@ pub fn exec_return(vm: &mut LuaVM, instr: u32) -> LuaResult<DispatchAction> {
1616 let _c = Instruction :: get_c ( instr) as usize ;
1717 let _k = Instruction :: get_k ( instr) ;
1818
19+ // Close upvalues before popping the frame
20+ let base_ptr = vm. current_frame ( ) . base_ptr ;
21+ vm. close_upvalues_from ( base_ptr) ;
22+
1923 let frame = vm. frames . pop ( ) . ok_or_else ( || {
2024 LuaError :: RuntimeError ( "RETURN with no frame on stack" . to_string ( ) )
2125 } ) ?;
@@ -1083,6 +1087,10 @@ pub fn exec_tailcall(vm: &mut LuaVM, instr: u32) -> LuaResult<DispatchAction> {
10831087/// RETURN0
10841088/// return (no values)
10851089pub fn exec_return0 ( vm : & mut LuaVM , _instr : u32 ) -> LuaResult < DispatchAction > {
1090+ // Close upvalues before popping the frame
1091+ let base_ptr = vm. current_frame ( ) . base_ptr ;
1092+ vm. close_upvalues_from ( base_ptr) ;
1093+
10861094 let frame = vm. frames . pop ( ) . ok_or_else ( || {
10871095 LuaError :: RuntimeError ( "RETURN0 with no frame on stack" . to_string ( ) )
10881096 } ) ?;
@@ -1115,6 +1123,10 @@ pub fn exec_return0(vm: &mut LuaVM, _instr: u32) -> LuaResult<DispatchAction> {
11151123pub fn exec_return1 ( vm : & mut LuaVM , instr : u32 ) -> LuaResult < DispatchAction > {
11161124 let a = Instruction :: get_a ( instr) as usize ;
11171125
1126+ // Close upvalues before popping the frame
1127+ let base_ptr = vm. current_frame ( ) . base_ptr ;
1128+ vm. close_upvalues_from ( base_ptr) ;
1129+
11181130 let frame = vm. frames . pop ( ) . ok_or_else ( || {
11191131 LuaError :: RuntimeError ( "RETURN1 with no frame on stack" . to_string ( ) )
11201132 } ) ?;
0 commit comments