mirror of
https://github.com/genodelabs/genode.git
synced 2025-03-23 04:25:21 +00:00
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:
parent
6947bddd3f
commit
9ec66f0594
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user