diff --git a/repos/dde_linux/src/lib/lx_kit/memory.cc b/repos/dde_linux/src/lib/lx_kit/memory.cc index 0d713b2a40..7e8a3f05da 100644 --- a/repos/dde_linux/src/lib/lx_kit/memory.cc +++ b/repos/dde_linux/src/lib/lx_kit/memory.cc @@ -57,16 +57,19 @@ Genode::Dataspace_capability Lx_kit::Mem_allocator::attached_dataspace_cap(void } -void * Lx_kit::Mem_allocator::alloc(size_t size, size_t align) +void * Lx_kit::Mem_allocator::alloc(size_t const size, size_t const align) { if (!size) return nullptr; + auto cleared_allocation = [] (void * const ptr, size_t const size) { + memset(ptr, 0, size); + return ptr; + }; + return _mem.alloc_aligned(size, (unsigned)log2(align)).convert( - [&] (void *ptr) { - memset(ptr, 0, size); - return ptr; }, + [&] (void *ptr) { return cleared_allocation(ptr, size); }, [&] (Range_allocator::Alloc_error) { @@ -92,9 +95,7 @@ void * Lx_kit::Mem_allocator::alloc(size_t size, size_t align) /* re-try allocation */ return _mem.alloc_aligned(size, (unsigned)log2(align)).convert( - [&] (void *ptr) { - memset(ptr, 0, size); - return ptr; }, + [&] (void *ptr) { return cleared_allocation(ptr, size); }, [&] (Range_allocator::Alloc_error) -> void * { error("memory allocation failed for ", size, " align ", align);