mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-03-12 09:33:59 -03:00
AP_Scripting: always free the heap and remove scripts
This commit is contained in:
parent
985e24275a
commit
66cdfb015b
@ -37,6 +37,10 @@ lua_scripts::lua_scripts(const AP_Int32 &vm_steps, const AP_Int32 &heap_size, co
|
|||||||
_heap = hal.util->allocate_heap_memory(heap_size);
|
_heap = hal.util->allocate_heap_memory(heap_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lua_scripts::~lua_scripts() {
|
||||||
|
free(_heap);
|
||||||
|
}
|
||||||
|
|
||||||
void lua_scripts::hook(lua_State *L, lua_Debug *ar) {
|
void lua_scripts::hook(lua_State *L, lua_Debug *ar) {
|
||||||
lua_scripts::overtime = true;
|
lua_scripts::overtime = true;
|
||||||
|
|
||||||
@ -535,4 +539,19 @@ void lua_scripts::run(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure all scripts have been removed
|
||||||
|
while (scripts != nullptr) {
|
||||||
|
remove_script(lua_state, scripts);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lua_state != nullptr) {
|
||||||
|
lua_close(lua_state); // shutdown the old state
|
||||||
|
lua_state = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error_msg_buf != nullptr) {
|
||||||
|
hal.util->heap_realloc(_heap, error_msg_buf, 0);
|
||||||
|
error_msg_buf = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,9 +53,9 @@ class lua_scripts
|
|||||||
public:
|
public:
|
||||||
lua_scripts(const AP_Int32 &vm_steps, const AP_Int32 &heap_size, const AP_Int8 &debug_options, struct AP_Scripting::terminal_s &_terminal);
|
lua_scripts(const AP_Int32 &vm_steps, const AP_Int32 &heap_size, const AP_Int8 &debug_options, struct AP_Scripting::terminal_s &_terminal);
|
||||||
|
|
||||||
/* Do not allow copies */
|
~lua_scripts();
|
||||||
lua_scripts(const lua_scripts &other) = delete;
|
|
||||||
lua_scripts &operator=(const lua_scripts&) = delete;
|
CLASS_NO_COPY(lua_scripts);
|
||||||
|
|
||||||
// return true if initialisation failed
|
// return true if initialisation failed
|
||||||
bool heap_allocated() const { return _heap != nullptr; }
|
bool heap_allocated() const { return _heap != nullptr; }
|
||||||
|
Loading…
Reference in New Issue
Block a user