diff --git a/repos/base/src/lib/base/allocator_avl.cc b/repos/base/src/lib/base/allocator_avl.cc index a176db06a..39fc615be 100644 --- a/repos/base/src/lib/base/allocator_avl.cc +++ b/repos/base/src/lib/base/allocator_avl.cc @@ -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; }