Skip to content

Commit

Permalink
fix page collection where a freed segment could be accessed
Browse files Browse the repository at this point in the history
  • Loading branch information
daanx committed May 13, 2024
1 parent 7b2e9c6 commit d824b9d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ static bool mi_heap_page_collect(mi_heap_t* heap, mi_page_queue_t* pq, mi_page_t
mi_assert_internal(mi_heap_page_is_valid(heap, pq, page, NULL, NULL));
mi_collect_t collect = *((mi_collect_t*)arg_collect);
_mi_page_free_collect(page, collect >= MI_FORCE);
if (collect == MI_FORCE) {
// note: call before a potential `_mi_page_free` as the segment may be freed if this was the last used page in that segment.
mi_segment_t* segment = _mi_page_segment(page);
_mi_segment_collect(segment, true /* force? */, &heap->tld->segments);
}
if (mi_page_all_free(page)) {
// no more used blocks, free the page.
// note: this will free retired pages as well.
Expand All @@ -104,10 +109,6 @@ static bool mi_heap_page_collect(mi_heap_t* heap, mi_page_queue_t* pq, mi_page_t
// still used blocks but the thread is done; abandon the page
_mi_page_abandon(page, pq);
}
if (collect == MI_FORCE) {
mi_segment_t* segment = _mi_page_segment(page);
_mi_segment_collect(segment, true /* force? */, &heap->tld->segments);
}
return true; // don't break
}

Expand Down

0 comments on commit d824b9d

Please sign in to comment.