From e0fef69cb34e6b3635c797114bf2e7f2d8ff16ad Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Thu, 19 Jan 2017 14:49:26 +0100 Subject: [PATCH] test/ram_fs_chunk: fix bug in allocation tracking In the past, the Genode::destroy, that is called by the RAM-FS-chunk destructors, issued Allocator::free instead of the C++ delete. Therefore it was possible to use the size argument of Allocator::free for the allocation tracker in the RAM-FS-chunk test. Nowadays, we have to keep track of the allocation sizes ourselves because delete doesn't hand over the size. Ref #1987 --- repos/os/src/test/ram_fs_chunk/main.cc | 27 +++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/repos/os/src/test/ram_fs_chunk/main.cc b/repos/os/src/test/ram_fs_chunk/main.cc index ead9a0798b..a458fa3d9b 100644 --- a/repos/os/src/test/ram_fs_chunk/main.cc +++ b/repos/os/src/test/ram_fs_chunk/main.cc @@ -21,8 +21,20 @@ namespace Genode { struct Allocator_tracer : Allocator { - size_t _sum; - Allocator &_wrapped; + struct Alloc + { + using Id = Id_space::Id; + + Id_space::Element id_space_elem; + size_t size; + + Alloc(Id_space &space, Id id, size_t size) + : id_space_elem(*this, space, id), size(size) { } + }; + + Id_space _allocs; + size_t _sum; + Allocator &_wrapped; Allocator_tracer(Allocator &wrapped) : _sum(0), _wrapped(wrapped) { } @@ -31,13 +43,18 @@ namespace Genode { bool alloc(size_t size, void **out_addr) { _sum += size; - return _wrapped.alloc(size, out_addr); + bool result = _wrapped.alloc(size, out_addr); + new (_wrapped) Alloc(_allocs, Alloc::Id { (addr_t)*out_addr }, size); + return result; } void free(void *addr, size_t size) { - _sum -= size; - _wrapped.free(addr, size); + _allocs.apply(Alloc::Id { (addr_t)addr }, [&] (Alloc &alloc) { + _sum -= alloc.size; + destroy(_wrapped, &alloc); + _wrapped.free(addr, size); + }); } size_t overhead(size_t size) const override { return _wrapped.overhead(size); }