void malloc_free(malloc_t *heap, void *ptr) { int type = heap->mem_map[(uintptr_t)ptr / RUN_SIZE]; if (ptr == NULL) return; if (type == MM_UNALLOCATED) { /* either large or bad address */ large_free(heap, ptr); } else if (type == MM_SMALL) { small_free(heap, ptr); } else if (type == MM_TINY) { tiny_free(heap, ptr); } else { DBG_ASSERT(0 && "Bad memory type"); } }
void free(void *ptr) { tag page_type = get_page_type(ptr); switch(page_type) { case TYPE_MEDIUM: medium_free(ptr); return; case TYPE_SMALL: small_free(ptr); return; case TYPE_BIG: big_free(ptr); return; } }
void free(void *ptr) { /* let them free null */ if (!ptr) return; /* see if it was a small malloc */ if (small_free(ptr)) return; /* must've been a big malloc */ big_free(ptr); }