AP_Scripting: fixed use after free bug

found with valgrind
This commit is contained in:
Andrew Tridgell 2023-12-29 09:45:38 +11:00
parent 1d0fc4e87c
commit 6fb99d6b1e
1 changed files with 6 additions and 7 deletions

View File

@ -402,19 +402,18 @@ void lua_scripts::remove_script(lua_State *L, script_info *script) {
}
}
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;
}
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);
}
void lua_scripts::reschedule_script(script_info *script) {