AP_NavEKF: allow init twice

this can happen if setup_core() fails with low mem and is called again
This commit is contained in:
Andrew Tridgell 2020-11-17 14:27:38 +11:00
parent 1e4b1d7563
commit fe81387433

View File

@ -14,6 +14,9 @@ ekf_ring_buffer::ekf_ring_buffer(uint8_t _elsize) :
bool ekf_ring_buffer::init(uint8_t size)
{
if (buffer) {
free(buffer);
}
buffer = calloc(size, elsize);
if (buffer == nullptr) {
return false;
@ -141,6 +144,10 @@ void *ekf_imu_buffer::get_offset(uint8_t idx) const
// initialise buffer, returns false when allocation has failed
bool ekf_imu_buffer::init(uint32_t size)
{
if (buffer != nullptr) {
// allow for init twive
free(buffer);
}
buffer = calloc(size, elsize);
if (buffer == nullptr) {
return false;