Skip to content

Commit fe81387

Browse files
committed
AP_NavEKF: allow init twice
this can happen if setup_core() fails with low mem and is called again
1 parent 1e4b1d7 commit fe81387

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

libraries/AP_NavEKF/EKF_Buffer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ ekf_ring_buffer::ekf_ring_buffer(uint8_t _elsize) :
1414

1515
bool ekf_ring_buffer::init(uint8_t size)
1616
{
17+
if (buffer) {
18+
free(buffer);
19+
}
1720
buffer = calloc(size, elsize);
1821
if (buffer == nullptr) {
1922
return false;
@@ -141,6 +144,10 @@ void *ekf_imu_buffer::get_offset(uint8_t idx) const
141144
// initialise buffer, returns false when allocation has failed
142145
bool ekf_imu_buffer::init(uint32_t size)
143146
{
147+
if (buffer != nullptr) {
148+
// allow for init twive
149+
free(buffer);
150+
}
144151
buffer = calloc(size, elsize);
145152
if (buffer == nullptr) {
146153
return false;

0 commit comments

Comments
 (0)