@@ -409,12 +409,12 @@ void *gc_alloc(size_t n_bytes, bool has_finaliser) {
409
409
void * ret_ptr = (void * )(MP_STATE_MEM (gc_pool_start ) + start_block * BYTES_PER_BLOCK );
410
410
DEBUG_printf ("gc_alloc(%p)\n" , ret_ptr );
411
411
412
- // zero out the additional bytes of the newly allocated blocks
412
+ // Zero out all the bytes of the newly allocated blocks.
413
413
// This is needed because the blocks may have previously held pointers
414
414
// to the heap and will not be set to something else if the caller
415
415
// doesn't actually use the entire block. As such they will continue
416
416
// to point to the heap and may prevent other blocks from being reclaimed.
417
- memset ((byte * )ret_ptr + n_bytes , 0 , (end_block - start_block + 1 ) * BYTES_PER_BLOCK - n_bytes );
417
+ memset ((byte * )ret_ptr , 0 , (end_block - start_block + 1 ) * BYTES_PER_BLOCK );
418
418
419
419
#if MICROPY_ENABLE_FINALISER
420
420
if (has_finaliser ) {
@@ -620,8 +620,8 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
620
620
ATB_FREE_TO_TAIL (bl );
621
621
}
622
622
623
- // zero out the additional bytes of the newly allocated blocks (see comment above in gc_alloc)
624
- memset ((byte * )ptr_in + n_bytes , 0 , new_blocks * BYTES_PER_BLOCK - n_bytes );
623
+ // zero out the bytes of the newly allocated blocks (see comment above in gc_alloc)
624
+ memset ((byte * )ptr_in + n_blocks * BYTES_PER_BLOCK , 0 , ( new_blocks - n_blocks ) * BYTES_PER_BLOCK );
625
625
626
626
#if EXTENSIVE_HEAP_PROFILING
627
627
gc_dump_alloc_table ();
0 commit comments