From 2f97c2d747b15f6b97082367bdcddfc5e44424a8 Mon Sep 17 00:00:00 2001 From: Dustin Crossman Date: Mon, 24 Feb 2020 11:10:17 -0800 Subject: [PATCH] Add check so that FlashIAP does not allocate memory on flash_init failure. --- drivers/source/FlashIAP.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/source/FlashIAP.cpp b/drivers/source/FlashIAP.cpp index 163a345689..b1c263d811 100644 --- a/drivers/source/FlashIAP.cpp +++ b/drivers/source/FlashIAP.cpp @@ -59,8 +59,12 @@ int FlashIAP::init() ret = -1; } } - uint32_t page_size = get_page_size(); - _page_buf = new uint8_t[page_size]; + + // Do not allocate if flash_init failed + if (ret == 0) { + uint32_t page_size = get_page_size(); + _page_buf = new uint8_t[page_size]; + } _mutex->unlock(); return ret;