From 54c3e7f74b53795936720a664ee4fbaf7f7a5e3d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 2 Jan 2023 08:33:22 +1100 Subject: [PATCH] AP_HAL_Linux: check for alloc failure of ObjectBuffer --- libraries/AP_HAL_Linux/OpticalFlow_Onboard.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/AP_HAL_Linux/OpticalFlow_Onboard.cpp b/libraries/AP_HAL_Linux/OpticalFlow_Onboard.cpp index 1c58a5223b..981afc77bb 100644 --- a/libraries/AP_HAL_Linux/OpticalFlow_Onboard.cpp +++ b/libraries/AP_HAL_Linux/OpticalFlow_Onboard.cpp @@ -171,6 +171,11 @@ void OpticalFlow_Onboard::init() } _gyro_ring_buffer = new ObjectBuffer(OPTICAL_FLOW_GYRO_BUFFER_LEN); + if (_gyro_ring_buffer != nullptr && _gyro_ring_buffer->get_size() == 0) { + // allocation failed + delete _gyro_ring_buffer; + _gyro_ring_buffer = nullptr; + } _initialized = true; }