From 1716105e738b91120905b53dddac389c39ce38dd Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 14 Jan 2022 19:01:51 +0200 Subject: Tests: Unmap memory ranges on /dev/mem after testing mmap(2) --- Tests/Kernel/TestMemoryDeviceMmap.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Tests/Kernel/TestMemoryDeviceMmap.cpp b/Tests/Kernel/TestMemoryDeviceMmap.cpp index ef4a21ee80..40a983dce4 100644 --- a/Tests/Kernel/TestMemoryDeviceMmap.cpp +++ b/Tests/Kernel/TestMemoryDeviceMmap.cpp @@ -23,7 +23,11 @@ static ALWAYS_INLINE bool mem_chunk(int fd, u64 base, u64 length) { u64 mmoffset = base % sysconf(_SC_PAGESIZE); void* mmp = mmap(NULL, mmoffset + length, PROT_READ, MAP_SHARED, fd, base - mmoffset); - return mmp != MAP_FAILED; + if (mmp == MAP_FAILED) + return false; + if (munmap(mmp, mmoffset + length) < 0) + perror("munmap"); + return true; } enum class ReadResult { -- cgit v1.2.3