From cf2886dc8f8d5f9d6ad70a8a2150781a96f02b00 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Thu, 24 Aug 2017 13:23:02 +0200 Subject: [PATCH] core: avoid freeing memory of unknown state This should actually never happen. However if it happens, be a bit robuster and don't provide the memory for re-use (which causes tons of other trouble afterwards). Issue #2505 --- repos/base/src/core/core_mem_alloc.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/repos/base/src/core/core_mem_alloc.cc b/repos/base/src/core/core_mem_alloc.cc index fe90ef417b..fcd7fed878 100644 --- a/repos/base/src/core/core_mem_alloc.cc +++ b/repos/base/src/core/core_mem_alloc.cc @@ -77,7 +77,13 @@ void Mapped_mem_allocator::free(void *addr, size_t size) Block *b = static_cast(_virt_alloc->_find_by_address((addr_t)addr)); if (!b) return; - _unmap_local((addr_t)addr, (addr_t)b->map_addr, b->size()); + if (!_unmap_local((addr_t)addr, (addr_t)b->map_addr, b->size())) { + Genode::error("error on unmap virt=", addr, " phys=", + Hex_range((addr_t)b->map_addr, b->size())); + /* leak physical and virtual region because of unknown usage state */ + return; + } + _phys_alloc->free(b->map_addr, b->size()); _virt_alloc->free(addr, b->size()); }