Skip to content

Commit

Permalink
AP_Scripting: fixed use after free bug
Browse files Browse the repository at this point in the history
found with valgrind
  • Loading branch information
tridge committed Dec 29, 2023
1 parent 1d0fc4e commit 6fb99d6
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions libraries/AP_Scripting/lua_scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,19 +402,18 @@ void lua_scripts::remove_script(lua_State *L, script_info *script) {
}
}

{
// Remove from running checksum
WITH_SEMAPHORE(crc_sem);
running_checksum ^= script->crc;
}

if (L != nullptr) {
// state could be null if we are force killing all scripts
luaL_unref(L, LUA_REGISTRYINDEX, script->lua_ref);
}
_heap.deallocate(script->name);
_heap.deallocate(script);

{
// Remove from running checksum
WITH_SEMAPHORE(crc_sem);
running_checksum ^= script->crc;
}

}

void lua_scripts::reschedule_script(script_info *script) {
Expand Down

0 comments on commit 6fb99d6

Please sign in to comment.