Guard slabcur fetching in extent_util

This commit is contained in:
Yinan Zhang 2019-10-28 09:24:42 -07:00
parent 4786099a3a
commit bd6e28d6a3
3 changed files with 11 additions and 7 deletions

View File

@ -3199,7 +3199,8 @@ label_return:
* otherwise their values are undefined. * otherwise their values are undefined.
* *
* This API is mainly intended for small class allocations, where extents are * This API is mainly intended for small class allocations, where extents are
* used as slab. * used as slab. Note that if the bin the extent belongs to is completely
* full, "(a)" will be NULL.
* *
* In case of large class allocations, "(a)" will be NULL, and "(e)" and "(f)" * In case of large class allocations, "(a)" will be NULL, and "(e)" and "(f)"
* will be zero (if stats are enabled; otherwise undefined). The other three * will be zero (if stats are enabled; otherwise undefined). The other three

View File

@ -2124,7 +2124,12 @@ extent_util_stats_verbose_get(tsdn_t *tsdn, const void *ptr,
} else { } else {
*bin_nfree = *bin_nregs = 0; *bin_nfree = *bin_nregs = 0;
} }
*slabcur_addr = extent_addr_get(bin->slabcur); extent_t *slab;
assert(*slabcur_addr != NULL); if (bin->slabcur != NULL) {
slab = bin->slabcur;
} else {
slab = extent_heap_first(&bin->slabs_nonfull);
}
*slabcur_addr = slab != NULL ? extent_addr_get(slab) : NULL;
malloc_mutex_unlock(tsdn, &bin->lock); malloc_mutex_unlock(tsdn, &bin->lock);
} }

View File

@ -94,10 +94,8 @@ TEST_BEGIN(test_query) {
"Extent region count exceeded size"); "Extent region count exceeded size");
assert_zu_ne(NREGS_READ(out), 0, assert_zu_ne(NREGS_READ(out), 0,
"Extent region count must be positive"); "Extent region count must be positive");
assert_ptr_not_null(SLABCUR_READ(out), assert_true(NFREE_READ(out) == 0 || (SLABCUR_READ(out)
"Current slab is null"); != NULL && SLABCUR_READ(out) <= p),
assert_true(NFREE_READ(out) == 0
|| SLABCUR_READ(out) <= p,
"Allocation should follow first fit principle"); "Allocation should follow first fit principle");
if (config_stats) { if (config_stats) {
assert_zu_le(BIN_NFREE_READ(out), assert_zu_le(BIN_NFREE_READ(out),