Hi Chao, > When recycling a context from the freelist, it only resets set->maxBlockSize > without recalculating set->allocChunkLimit, while set->allocChunkLimit is > derived from set->maxBlockSize. Nice find! It's clear that the reuse path diverges from the create path for setting allocChunkLimit.
> In summary, this bug doesn’t lead to memory leaks, but it breaks AllocSet’s > intended allocation behavior: sometimes causing unexpected malloc()/free() > calls, and sometimes unexpected pooling and memory retention. Per the comment you moved to the helper function, if allocChunkLimit doesn't follow the ALLOC_CHUNK_FRACTION formula, it could also lead to unexpected size of memory waste at a block's tail. > The fix is straightforward. I extracted the allocChunkLimit computation into > a shared helper and use it in both the creation and recycling paths. See the > attached patch for details. Since this code is very old, the fix might be > worth backpatching to all supported branches. The fix looks good to me. Regards, Donghang
