MCPcopy Index your code
hub / github.com/dcodeIO/webassembly / dispose_chunk

Function dispose_chunk

lib/dlmalloc/malloc.c:4358–4424  ·  view source on GitHub ↗

Consolidate and bin a chunk. Differs from exported versions of free mainly in that the chunk need not be marked as inuse. */

Source from the content-addressed store, hash-verified

4356 of free mainly in that the chunk need not be marked as inuse.
4357*/
4358static void dispose_chunk(mstate m, mchunkptr p, size_t psize) {
4359 mchunkptr next = chunk_plus_offset(p, psize);
4360 if (!pinuse(p)) {
4361 mchunkptr prev;
4362 size_t prevsize = p->prev_foot;
4363 if (is_mmapped(p)) {
4364 psize += prevsize + MMAP_FOOT_PAD;
4365 if (CALL_MUNMAP((char*)p - prevsize, psize) == 0)
4366 m->footprint -= psize;
4367 return;
4368 }
4369 prev = chunk_minus_offset(p, prevsize);
4370 psize += prevsize;
4371 p = prev;
4372 if (RTCHECK(ok_address(m, prev))) { /* consolidate backward */
4373 if (p != m->dv) {
4374 unlink_chunk(m, p, prevsize);
4375 }
4376 else if ((next->head & INUSE_BITS) == INUSE_BITS) {
4377 m->dvsize = psize;
4378 set_free_with_pinuse(p, psize, next);
4379 return;
4380 }
4381 }
4382 else {
4383 CORRUPTION_ERROR_ACTION(m);
4384 return;
4385 }
4386 }
4387 if (RTCHECK(ok_address(m, next))) {
4388 if (!cinuse(next)) { /* consolidate forward */
4389 if (next == m->top) {
4390 size_t tsize = m->topsize += psize;
4391 m->top = p;
4392 p->head = tsize | PINUSE_BIT;
4393 if (p == m->dv) {
4394 m->dv = 0;
4395 m->dvsize = 0;
4396 }
4397 return;
4398 }
4399 else if (next == m->dv) {
4400 size_t dsize = m->dvsize += psize;
4401 m->dv = p;
4402 set_size_and_pinuse_of_free_chunk(p, dsize);
4403 return;
4404 }
4405 else {
4406 size_t nsize = chunksize(next);
4407 psize += nsize;
4408 unlink_chunk(m, next, nsize);
4409 set_size_and_pinuse_of_free_chunk(p, psize);
4410 if (p == m->dv) {
4411 m->dvsize = psize;
4412 return;
4413 }
4414 }
4415 }

Callers 3

try_realloc_chunkFunction · 0.85
internal_memalignFunction · 0.85
internal_bulk_freeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected