Merge pull request #2369 from jepler/nrf-usb-crash

Fix crashes while copying files to nRF via USB
crypto-aes
Scott Shawcroft 3 years ago committed by GitHub
commit ce8d400819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -667,6 +667,9 @@ void gc_free(void *ptr) {
if (ptr == NULL) {
GC_EXIT();
} else {
if (MP_STATE_MEM(gc_pool_start) == 0) {
reset_into_safe_mode(GC_ALLOC_OUTSIDE_VM);
}
// get the GC block number corresponding to this pointer
assert(VERIFY_PTR(ptr));
size_t block = BLOCK_FROM_PTR(ptr);

@ -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;
@ -367,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;
@ -415,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]);
}
}

Loading…
Cancel
Save