Rework free list so that 0 is the placeholder.

This is needed because in some configurations the constructor for the
global placeholder is not called before the first allocation (i.e. when
other globals call the allocator in their constructor) and so we ended
up following a null pointer.
This commit is contained in:
David Chisnall
2019-07-05 14:20:24 +01:00
parent 14b5c57b55
commit 2efcddfc3d
4 changed files with 13 additions and 11 deletions

View File

@@ -1072,7 +1072,7 @@ namespace snmalloc
assert(sizeclass < NUM_SMALL_CLASSES);
auto& fl = small_fast_free_lists[sizeclass];
auto head = fl.value;
if (likely((reinterpret_cast<size_t>(head) & 1) == 0))
if (likely(head != nullptr))
{
void* p = head;
// Read the next slot from the memory that's about to be allocated.