Skip to content

Commit f4a5c17

Browse files
committed
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: adafruit#2338 (together with previous commit)
1 parent b22fbcd commit f4a5c17

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

supervisor/shared/external_flash/external_flash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ static void release_ram_cache(void) {
371371
if (supervisor_cache != NULL) {
372372
free_memory(supervisor_cache);
373373
supervisor_cache = NULL;
374-
} else {
374+
} else if (MP_STATE_MEM(gc_pool_start)) {
375375
m_free(MP_STATE_VM(flash_ram_cache));
376376
}
377377
MP_STATE_VM(flash_ram_cache) = NULL;
@@ -419,7 +419,7 @@ static bool flush_ram_cache(bool keep_cache) {
419419
write_flash(current_sector + (i * pages_per_block + j) * SPI_FLASH_PAGE_SIZE,
420420
MP_STATE_VM(flash_ram_cache)[i * pages_per_block + j],
421421
SPI_FLASH_PAGE_SIZE);
422-
if (!keep_cache && supervisor_cache == NULL) {
422+
if (!keep_cache && supervisor_cache == NULL && MP_STATE_MEM(gc_pool_start)) {
423423
m_free(MP_STATE_VM(flash_ram_cache)[i * pages_per_block + j]);
424424
}
425425
}

0 commit comments

Comments
 (0)