From d9c98757683d3cdfe7af302d9bc5cfbeb0026baf Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 2 May 2023 10:39:16 +1000 Subject: [PATCH] AP_NavEKF2: 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_NavEKF2/AP_NavEKF2.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/AP_NavEKF2/AP_NavEKF2.cpp b/libraries/AP_NavEKF2/AP_NavEKF2.cpp index 9c8ab40199..e4fce86ef7 100644 --- a/libraries/AP_NavEKF2/AP_NavEKF2.cpp +++ b/libraries/AP_NavEKF2/AP_NavEKF2.cpp @@ -662,6 +662,7 @@ bool NavEKF2::InitialiseFilter(void) if (AP::dal().available_memory() < sizeof(NavEKF2_core)*num_cores + 4096) { initFailure = InitFailures::NO_MEM; core_malloc_failed = true; + num_cores = 0; GCS_SEND_TEXT(MAV_SEVERITY_CRITICAL, "NavEKF2: not enough memory available"); return false; } @@ -671,6 +672,7 @@ bool NavEKF2::InitialiseFilter(void) if (core == nullptr) { initFailure = InitFailures::NO_MEM; core_malloc_failed = true; + num_cores = 0; GCS_SEND_TEXT(MAV_SEVERITY_CRITICAL, "NavEKF2: memory allocation failed"); return false; }