When a non-thread-local block is freed, it becomes part of the thread delayed free list that is freed later by the owning heap. If the exact usable size is too small to contain the pointer for the delayed list, then shrink the padding (by decreasing delta) so it will later not trigger an overflow error in `mi_free_block`.
| 286 | // contain the pointer for the delayed list, then shrink the padding (by decreasing delta) |
| 287 | // so it will later not trigger an overflow error in `mi_free_block`. |
| 288 | static void mi_padding_shrink(const mi_page_t* page, const mi_block_t* block, const size_t min_size) { |
| 289 | size_t bsize; |
| 290 | size_t delta; |
| 291 | bool ok = mi_page_decode_padding(page, block, &delta, &bsize); |
| 292 | mi_assert_internal(ok); |
| 293 | if (!ok || (bsize - delta) >= min_size) return; // usually already enough space |
| 294 | mi_assert_internal(bsize >= min_size); |
| 295 | if (bsize < min_size) return; // should never happen |
| 296 | size_t new_delta = (bsize - min_size); |
| 297 | mi_assert_internal(new_delta < bsize); |
| 298 | mi_padding_t* padding = (mi_padding_t*)((uint8_t*)block + bsize); |
| 299 | padding->delta = (uint32_t)new_delta; |
| 300 | } |
| 301 | #else |
| 302 | static void mi_check_padding(const mi_page_t* page, const mi_block_t* block) { |
| 303 | MI_UNUSED(page); |
no test coverage detected