microsoft / mimalloc

mimalloc is a compact general purpose allocator with excellent performance.
MIT License
10.52k stars 852 forks source link

Incorrect masks used in mi_bitmap_is_claimedx_across #368

Open carey opened 3 years ago

carey commented 3 years ago

In mi_bitmap_is_claimedx_across, the middle fields and the post field all compare the field contents against pre_mask. Compared to the preceding functions, it looks like these should be using mid_mask and post_mask, respectively.

I can’t say if this has caused any issues; I've just been reading the code to understand how the atomic operations work.

daanx commented 3 years ago

OMG! That is a terrible bug :( -- I pushed a fix and will push out a new mimalloc release this week.

It turns out to be relatively benign as one would only observe it when (manually) reserving a huge arena (over 2GiB) and allocating a large allocations across the block boundaries. However, for the last few weeks I have been looking into a service that mysteriously leaks very slowly memory over weeks and I now think this bug may be the culprit. fingers crossed.

Thanks so much for spotting this! -- embarrassing error; I am now going over the code in detail again and see if there are other problems as well.