From 52cb59e61d5bfcca75e47dc8f3d0d712a8544cbd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 2 May 2023 10:39:16 +1000 Subject: [PATCH] AP_NavEKF3: handle core setup failure ensure num_cores is left as zero so that calls such as Log_Write don't de-reference nullptr --- libraries/AP_NavEKF3/AP_NavEKF3.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/AP_NavEKF3/AP_NavEKF3.cpp b/libraries/AP_NavEKF3/AP_NavEKF3.cpp index 566d202e4f..c198b20bc2 100644 --- a/libraries/AP_NavEKF3/AP_NavEKF3.cpp +++ b/libraries/AP_NavEKF3/AP_NavEKF3.cpp @@ -803,6 +803,7 @@ bool NavEKF3::InitialiseFilter(void) if (AP::dal().available_memory() < sizeof(NavEKF3_core)*num_cores + 4096) { GCS_SEND_TEXT(MAV_SEVERITY_CRITICAL, "EKF3 not enough memory"); _enable.set(0); + num_cores = 0; return false; } @@ -810,6 +811,7 @@ bool NavEKF3::InitialiseFilter(void) core = (NavEKF3_core*)AP::dal().malloc_type(sizeof(NavEKF3_core)*num_cores, AP::dal().MEM_FAST); if (core == nullptr) { _enable.set(0); + num_cores = 0; GCS_SEND_TEXT(MAV_SEVERITY_CRITICAL, "EKF3 allocation failed"); return false; }