allocator_avl: simplify structure

This patch changes the code of '_alloc_two_blocks_metadata' to not
leak the result of a partial allocation in the out parameters of
the method. This eases the reasoning about the absence of a
use-atfer-free problem (there was none).
This commit is contained in:
Norman Feske 2020-01-07 15:58:52 +01:00 committed by Christian Helmuth
parent 6947bddd3f
commit 9ec66f0594
1 changed files with 13 additions and 5 deletions

View File

@ -107,13 +107,21 @@ Allocator_avl_base::Block *Allocator_avl_base::_alloc_block_metadata()
bool Allocator_avl_base::_alloc_two_blocks_metadata(Block **dst1, Block **dst2)
{
*dst1 = _alloc_block_metadata();
*dst2 = _alloc_block_metadata();
Block * const b1 = _alloc_block_metadata();
Block * const b2 = _alloc_block_metadata();
if (!*dst1 && *dst2) _md_alloc->free(*dst2, sizeof(Block));
if (!*dst2 && *dst1) _md_alloc->free(*dst1, sizeof(Block));
if (b1 && b2) {
*dst1 = b1;
*dst2 = b2;
return true;
}
return (*dst1 && *dst2);
*dst1 = *dst2 = nullptr;
if (b2) _md_alloc->free(b2, sizeof(Block));
if (b1) _md_alloc->free(b1, sizeof(Block));
return false;
}