File tree 2 files changed +9
-2
lines changed
supervisor/shared/external_flash 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -667,6 +667,9 @@ void gc_free(void *ptr) {
667
667
if (ptr == NULL ) {
668
668
GC_EXIT ();
669
669
} else {
670
+ if (MP_STATE_MEM (gc_pool_start ) == 0 ) {
671
+ reset_into_safe_mode (GC_ALLOC_OUTSIDE_VM );
672
+ }
670
673
// get the GC block number corresponding to this pointer
671
674
assert (VERIFY_PTR (ptr ));
672
675
size_t block = BLOCK_FROM_PTR (ptr );
Original file line number Diff line number Diff line change @@ -324,6 +324,10 @@ static bool allocate_ram_cache(void) {
324
324
return true;
325
325
}
326
326
327
+ if (MP_STATE_MEM (gc_pool_start ) == 0 ) {
328
+ return false;
329
+ }
330
+
327
331
MP_STATE_VM (flash_ram_cache ) = m_malloc_maybe (blocks_per_sector * pages_per_block * sizeof (uint32_t ), false);
328
332
if (MP_STATE_VM (flash_ram_cache ) == NULL ) {
329
333
return false;
@@ -367,7 +371,7 @@ static void release_ram_cache(void) {
367
371
if (supervisor_cache != NULL ) {
368
372
free_memory (supervisor_cache );
369
373
supervisor_cache = NULL ;
370
- } else {
374
+ } else if ( MP_STATE_MEM ( gc_pool_start )) {
371
375
m_free (MP_STATE_VM (flash_ram_cache ));
372
376
}
373
377
MP_STATE_VM (flash_ram_cache ) = NULL ;
@@ -415,7 +419,7 @@ static bool flush_ram_cache(bool keep_cache) {
415
419
write_flash (current_sector + (i * pages_per_block + j ) * SPI_FLASH_PAGE_SIZE ,
416
420
MP_STATE_VM (flash_ram_cache )[i * pages_per_block + j ],
417
421
SPI_FLASH_PAGE_SIZE );
418
- if (!keep_cache && supervisor_cache == NULL ) {
422
+ if (!keep_cache && supervisor_cache == NULL && MP_STATE_MEM ( gc_pool_start ) ) {
419
423
m_free (MP_STATE_VM (flash_ram_cache )[i * pages_per_block + j ]);
420
424
}
421
425
}
You can’t perform that action at this time.
0 commit comments