@@ -366,17 +366,17 @@ void *gc_alloc(machine_uint_t n_bytes, bool has_finaliser) {
366
366
// get pointer to first block
367
367
void * ret_ptr = (void * )(gc_pool_start + start_block * WORDS_PER_BLOCK );
368
368
369
- // zero out the newly allocated blocks
369
+ // zero out the additional bytes of the newly allocated blocks
370
370
// This is needed because the blocks may have previously held pointers
371
371
// to the heap and will not be set to something else if the caller
372
372
// doesn't actually use the entire block. As such they will continue
373
373
// to point to the heap and may prevent other blocks from being reclaimed.
374
- memset (ret_ptr , 0 , (end_block - start_block + 1 ) * BYTES_PER_BLOCK );
374
+ memset (ret_ptr + n_bytes , 0 , (end_block - start_block + 1 ) * BYTES_PER_BLOCK - n_bytes );
375
375
376
376
#if MICROPY_ENABLE_FINALISER
377
377
if (has_finaliser ) {
378
- // clear type pointer in case it is never set (now done above in memset)
379
- // ((mp_obj_base_t*)ret_ptr)->type = MP_OBJ_NULL;
378
+ // clear type pointer in case it is never set
379
+ ((mp_obj_base_t * )ret_ptr )-> type = MP_OBJ_NULL ;
380
380
// set mp_obj flag only if it has a finaliser
381
381
FTB_SET (start_block );
382
382
}
@@ -534,8 +534,8 @@ void *gc_realloc(void *ptr_in, machine_uint_t n_bytes) {
534
534
ATB_FREE_TO_TAIL (bl );
535
535
}
536
536
537
- // zero out the newly allocated blocks (see comment above in gc_alloc)
538
- memset (ptr_in + n_blocks * BYTES_PER_BLOCK , 0 , ( new_blocks - n_blocks ) * BYTES_PER_BLOCK );
537
+ // zero out the additional bytes of the newly allocated blocks (see comment above in gc_alloc)
538
+ memset (ptr_in + n_bytes , 0 , new_blocks * BYTES_PER_BLOCK - n_bytes );
539
539
540
540
return ptr_in ;
541
541
}
0 commit comments