> On Oct 17, 2026, at 08:47, Donghang Lin <[email protected]> wrote:
>
> 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.
Thanks a lot for your review.
>
>> 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.
Yes, that’s another consequence of stale larger allocChunkLimit.
>
>> 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.
>
Cool!
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/