From b22fbcd77da8c9724ed08228b89cfea53afdd5b6 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 10 Dec 2019 15:11:10 -0600 Subject: supervisor: external_flash: don't call m_malloc_maybe when it's bad --- supervisor/shared/external_flash/external_flash.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'supervisor') diff --git a/supervisor/shared/external_flash/external_flash.c b/supervisor/shared/external_flash/external_flash.c index 99df553e1..e7d86240b 100644 --- a/supervisor/shared/external_flash/external_flash.c +++ b/supervisor/shared/external_flash/external_flash.c @@ -324,6 +324,10 @@ static bool allocate_ram_cache(void) { return true; } + if (MP_STATE_MEM(gc_pool_start) == 0) { + return false; + } + MP_STATE_VM(flash_ram_cache) = m_malloc_maybe(blocks_per_sector * pages_per_block * sizeof(uint32_t), false); if (MP_STATE_VM(flash_ram_cache) == NULL) { return false; -- cgit v1.2.3 From f4a5c17b5e79cf9bd02be248620d445065891a25 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 10 Dec 2019 17:05:37 -0600 Subject: supervisor: external_flash: don't call m_free when it's bad It's extremely dubious that we have these handles that we think are to GC'd memory at a time when the gc pool may not be initialized. Hopefully, they WERE valid GC memory and are undisturbed by the teardown of the interpreter that can lead to this state. In this case, don't try to m_free them, the memory will become free when the GC heap is reinitialized. Closes: #2338 (together with previous commit) --- supervisor/shared/external_flash/external_flash.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'supervisor') diff --git a/supervisor/shared/external_flash/external_flash.c b/supervisor/shared/external_flash/external_flash.c index e7d86240b..9d38c07d8 100644 --- a/supervisor/shared/external_flash/external_flash.c +++ b/supervisor/shared/external_flash/external_flash.c @@ -371,7 +371,7 @@ static void release_ram_cache(void) { if (supervisor_cache != NULL) { free_memory(supervisor_cache); supervisor_cache = NULL; - } else { + } else if (MP_STATE_MEM(gc_pool_start)) { m_free(MP_STATE_VM(flash_ram_cache)); } MP_STATE_VM(flash_ram_cache) = NULL; @@ -419,7 +419,7 @@ static bool flush_ram_cache(bool keep_cache) { write_flash(current_sector + (i * pages_per_block + j) * SPI_FLASH_PAGE_SIZE, MP_STATE_VM(flash_ram_cache)[i * pages_per_block + j], SPI_FLASH_PAGE_SIZE); - if (!keep_cache && supervisor_cache == NULL) { + if (!keep_cache && supervisor_cache == NULL && MP_STATE_MEM(gc_pool_start)) { m_free(MP_STATE_VM(flash_ram_cache)[i * pages_per_block + j]); } } -- cgit v1.2.3