MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / mi_heap_free

Function mi_heap_free

3rd/mimalloc-2.0.9/src/heap.c:249–277  ·  view source on GitHub ↗

called from `mi_heap_destroy` and `mi_heap_delete` to free the internal heap resources.

Source from the content-addressed store, hash-verified

247
248// called from `mi_heap_destroy` and `mi_heap_delete` to free the internal heap resources.
249static void mi_heap_free(mi_heap_t* heap) {
250 mi_assert(heap != NULL);
251 mi_assert_internal(mi_heap_is_initialized(heap));
252 if (heap==NULL || !mi_heap_is_initialized(heap)) return;
253 if (mi_heap_is_backing(heap)) return; // dont free the backing heap
254
255 // reset default
256 if (mi_heap_is_default(heap)) {
257 _mi_heap_set_default_direct(heap->tld->heap_backing);
258 }
259
260 // remove ourselves from the thread local heaps list
261 // linear search but we expect the number of heaps to be relatively small
262 mi_heap_t* prev = NULL;
263 mi_heap_t* curr = heap->tld->heaps;
264 while (curr != heap && curr != NULL) {
265 prev = curr;
266 curr = curr->next;
267 }
268 mi_assert_internal(curr == heap);
269 if (curr == heap) {
270 if (prev != NULL) { prev->next = heap->next; }
271 else { heap->tld->heaps = heap->next; }
272 }
273 mi_assert_internal(heap->tld->heaps != NULL);
274
275 // and free the used memory
276 mi_free(heap);
277}
278
279
280/* -----------------------------------------------------------

Callers 2

mi_heap_destroyFunction · 0.85
mi_heap_deleteFunction · 0.85

Calls 5

mi_heap_is_initializedFunction · 0.85
mi_heap_is_backingFunction · 0.85
mi_heap_is_defaultFunction · 0.85
mi_freeFunction · 0.85

Tested by

no test coverage detected