Searching if an addr is in a malloc-ed client block is expensive (linear search)
So, before scanning the list of malloc block, check that the address is
in a client heap segment : this is a fast operation (it has a small
cache, and for cache miss, does a dichotomic search) and avoids
scanning a often big list (for big applications).
Int i;
const Int n_fast_check_words = 16;
+ /* Before searching the list of allocated blocks in hg_mallocmeta_table,
+ first verify that data_addr is in a heap client segment. */
+ const NSegment *s = VG_(am_find_nsegment) (data_addr);
+ if (s == NULL || !s->isCH)
+ return False;
+
/* First, do a few fast searches on the basis that data_addr might
be exactly the start of a block or up to 15 words inside. This
can happen commonly via the creq