MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / tmalloc_small

Function tmalloc_small

dlmalloc/dlmalloc.c:3934–3970  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

3932
3933/* allocate a small request from the best fitting chunk in a treebin */
3934static void* tmalloc_small(mstate m, size_t nb) {
3935 tchunkptr t, v;
3936 size_t rsize;
3937 bindex_t i;
3938 binmap_t leastbit = least_bit(m->treemap);
3939 compute_bit2idx(leastbit, i);
3940
3941 v = t = *treebin_at(m, i);
3942 rsize = chunksize(t) - nb;
3943
3944 while ((t = leftmost_child(t)) != 0) {
3945 size_t trem = chunksize(t) - nb;
3946 if (trem < rsize) {
3947 rsize = trem;
3948 v = t;
3949 }
3950 }
3951
3952 if (RTCHECK(ok_address(m, v))) {
3953 mchunkptr r = chunk_plus_offset(v, nb);
3954 assert(chunksize(v) == rsize + nb);
3955 if (RTCHECK(ok_next(v, r))) {
3956 unlink_large_chunk(m, v);
3957 if (rsize < MIN_CHUNK_SIZE)
3958 set_inuse_and_pinuse(m, v, (rsize + nb));
3959 else {
3960 set_size_and_pinuse_of_inuse_chunk(m, v, nb);
3961 set_size_and_pinuse_of_free_chunk(r, rsize);
3962 replace_dv(m, r, rsize);
3963 }
3964 return chunk2mem(v);
3965 }
3966 }
3967
3968 CORRUPTION_ERROR_ACTION(m);
3969 return 0;
3970}
3971
3972/* --------------------------- realloc support --------------------------- */
3973

Callers 2

dlmallocFunction · 0.85
alloc_from_reserved_memFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected