Skip to content

Commit

Permalink
AP_Scripting: make sure never to use removed script pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
IamPete1 committed Apr 23, 2024
1 parent f09b552 commit aa1faf5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions libraries/AP_Scripting/lua_scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ void lua_scripts::remove_script(lua_State *L, script_info *script) {
}
_heap.deallocate(script->name);
_heap.deallocate(script);
script = nullptr;
}

void lua_scripts::reschedule_script(script_info *script) {
Expand Down Expand Up @@ -670,9 +671,11 @@ void lua_scripts::run(void) {
hal.scheduler->restore_interrupts(istate);
#endif

script_to_run->memory += allocated - deallocated;

update_stats(script_to_run->name, runEnd - loadEnd, endMem, script_to_run->memory, allocated);
if (script_to_run != nullptr) {
// If script crashed in `run_next_script` it will be nullptr
script_to_run->memory += allocated - deallocated;
update_stats(script_to_run->name, runEnd - loadEnd, endMem, script_to_run->memory, allocated);
}

// Re-zero count for next script
allocated = 0;
Expand Down

0 comments on commit aa1faf5

Please sign in to comment.