Jinoh Kang (@iamahuman) commented about dlls/ntdll/heap.c:
- }
- affinity %= ARRAY_SIZE(category->affinity_group);
- /* acquire a group, the thread will own it and no other thread can clear free bits.
* some other thread might still set the free bits if they are freeing blocks.
*/
- if (!(group = heap_acquire_category_group( heap, flags, block_size, category ))) return NULL;
- /* serialize with heap_free_block_lfh: atomically set GROUP_FLAG_FREE when the free bits are all 0. */
- if (group_find_free_block( group, block_size, &block ))
InterlockedAnd( &group->free_bits, ~GROUP_FLAG_FREE );
- else
InterlockedCompareExchange( &group->free_bits, GROUP_FLAG_FREE, 0 );
- /* if GROUP_FLAG_FREE was set, thread released its ownership. */
- if (group->free_bits & GROUP_FLAG_FREE) return block;
I think it's better to remove the `return block` and embed the subsequent `if` instead. The `GROUP_FLAG_FREE` special case is not special enough to return a different block, so it's more clear to indicate that `GROUP_FLAG_FREE` has nothing to do with the returned block itself.