@@ -366,17 +366,17 @@ void *gc_alloc(machine_uint_t n_bytes, bool has_finaliser) {
366366 // get pointer to first block
367367 void * ret_ptr = (void * )(gc_pool_start + start_block * WORDS_PER_BLOCK );
368368
369- // zero out the newly allocated blocks
369+ // zero out the additional bytes of the newly allocated blocks
370370 // This is needed because the blocks may have previously held pointers
371371 // to the heap and will not be set to something else if the caller
372372 // doesn't actually use the entire block. As such they will continue
373373 // 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 );
375375
376376#if MICROPY_ENABLE_FINALISER
377377 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 ;
380380 // set mp_obj flag only if it has a finaliser
381381 FTB_SET (start_block );
382382 }
@@ -534,8 +534,8 @@ void *gc_realloc(void *ptr_in, machine_uint_t n_bytes) {
534534 ATB_FREE_TO_TAIL (bl );
535535 }
536536
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 );
539539
540540 return ptr_in ;
541541 }
0 commit comments