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

Function tmalloc_small

lib/dlmalloc/malloc.c:4500–4535  ·  view source on GitHub ↗

allocate a small request from the best fitting chunk in a treebin */

Source from the content-addressed store, hash-verified

4498
4499/* allocate a small request from the best fitting chunk in a treebin */
4500static void* tmalloc_small(mstate m, size_t nb) {
4501 tchunkptr t, v;
4502 size_t rsize;
4503 bindex_t i;
4504 binmap_t leastbit = least_bit(m->treemap);
4505 compute_bit2idx(leastbit, i);
4506 v = t = *treebin_at(m, i);
4507 rsize = chunksize(t) - nb;
4508
4509 while ((t = leftmost_child(t)) != 0) {
4510 size_t trem = chunksize(t) - nb;
4511 if (trem < rsize) {
4512 rsize = trem;
4513 v = t;
4514 }
4515 }
4516
4517 if (RTCHECK(ok_address(m, v))) {
4518 mchunkptr r = chunk_plus_offset(v, nb);
4519 assert(chunksize(v) == rsize + nb);
4520 if (RTCHECK(ok_next(v, r))) {
4521 unlink_large_chunk(m, v);
4522 if (rsize < MIN_CHUNK_SIZE)
4523 set_inuse_and_pinuse(m, v, (rsize + nb));
4524 else {
4525 set_size_and_pinuse_of_inuse_chunk(m, v, nb);
4526 set_size_and_pinuse_of_free_chunk(r, rsize);
4527 replace_dv(m, r, rsize);
4528 }
4529 return chunk2mem(v);
4530 }
4531 }
4532
4533 CORRUPTION_ERROR_ACTION(m);
4534 return 0;
4535}
4536
4537#if !ONLY_MSPACES
4538

Callers 2

dlmallocFunction · 0.85
mspace_mallocFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected