File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -536,37 +536,34 @@ void gc_free(void *ptr) {
536536
537537 DEBUG_printf ("gc_free(%p)\n" , ptr );
538538
539- if (VERIFY_PTR (ptr )) {
539+ if (ptr == NULL ) {
540+ GC_EXIT ();
541+ } else {
542+ // get the GC block number corresponding to this pointer
543+ assert (VERIFY_PTR (ptr ));
540544 size_t block = BLOCK_FROM_PTR (ptr );
541- if (ATB_GET_KIND (block ) == AT_HEAD ) {
542- #if MICROPY_ENABLE_FINALISER
543- FTB_CLEAR (block );
544- #endif
545- // set the last_free pointer to this block if it's earlier in the heap
546- if (block / BLOCKS_PER_ATB < MP_STATE_MEM (gc_last_free_atb_index )) {
547- MP_STATE_MEM (gc_last_free_atb_index ) = block / BLOCKS_PER_ATB ;
548- }
545+ assert (ATB_GET_KIND (block ) == AT_HEAD );
549546
550- // free head and all of its tail blocks
551- do {
552- ATB_ANY_TO_FREE (block );
553- block += 1 ;
554- } while (ATB_GET_KIND (block ) == AT_TAIL );
555-
556- GC_EXIT ();
547+ #if MICROPY_ENABLE_FINALISER
548+ FTB_CLEAR (block );
549+ #endif
557550
558- #if EXTENSIVE_HEAP_PROFILING
559- gc_dump_alloc_table ();
560- #endif
561- } else {
562- GC_EXIT ();
563- assert (!"bad free" );
551+ // set the last_free pointer to this block if it's earlier in the heap
552+ if (block / BLOCKS_PER_ATB < MP_STATE_MEM (gc_last_free_atb_index )) {
553+ MP_STATE_MEM (gc_last_free_atb_index ) = block / BLOCKS_PER_ATB ;
564554 }
565- } else if (ptr != NULL ) {
566- GC_EXIT ();
567- assert (!"bad free" );
568- } else {
555+
556+ // free head and all of its tail blocks
557+ do {
558+ ATB_ANY_TO_FREE (block );
559+ block += 1 ;
560+ } while (ATB_GET_KIND (block ) == AT_TAIL );
561+
569562 GC_EXIT ();
563+
564+ #if EXTENSIVE_HEAP_PROFILING
565+ gc_dump_alloc_table ();
566+ #endif
570567 }
571568}
572569
You can’t perform that action at this time.
0 commit comments