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

Function bin_find

dlmalloc/dlmalloc.c:2770–2803  ·  view source on GitHub ↗

Find x in a bin. Used in other check functions. */

Source from the content-addressed store, hash-verified

2768
2769/* Find x in a bin. Used in other check functions. */
2770static int bin_find(mstate m, mchunkptr x) {
2771 size_t size = chunksize(x);
2772 if (is_small(size)) {
2773 bindex_t sidx = small_index(size);
2774 sbinptr b = smallbin_at(m, sidx);
2775 if (smallmap_is_marked(m, sidx)) {
2776 mchunkptr p = b;
2777 do {
2778 if (p == x)
2779 return 1;
2780 } while ((p = p->fd) != b);
2781 }
2782 }
2783 else {
2784 bindex_t tidx;
2785 compute_tree_index(size, tidx);
2786 if (treemap_is_marked(m, tidx)) {
2787 tchunkptr t = *treebin_at(m, tidx);
2788 size_t sizebits = size << leftshift_for_tree_index(tidx);
2789 while (t != 0 && chunksize(t) != size) {
2790 t = t->child[(sizebits >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1];
2791 sizebits <<= 1;
2792 }
2793 if (t != 0) {
2794 tchunkptr u = t;
2795 do {
2796 if (u == (tchunkptr)x)
2797 return 1;
2798 } while ((u = u->fd) != t);
2799 }
2800 }
2801 }
2802 return 0;
2803}
2804
2805/* Traverse each chunk and check it; return total */
2806static size_t traverse_and_check(mstate m) {

Callers 2

traverse_and_checkFunction · 0.85
do_check_malloc_stateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected