diff --git a/kernel/src/memory/SharedMemory.cpp b/kernel/src/memory/SharedMemory.cpp index 92f3f78f..cb4b3ce0 100644 --- a/kernel/src/memory/SharedMemory.cpp +++ b/kernel/src/memory/SharedMemory.cpp @@ -107,12 +107,16 @@ Result SharedMemory::map(u64 virt, int flags, off_t _offset, usize count) void SharedMemory::free() { - if (inode && (prot & PROT_WRITE)) + if ((inode || device) && (prot & PROT_WRITE)) { for (u64 i = 0; i < frames.size(); i++) { - inode->write((u8*)MMU::translate_physical_address(frames[i]), offset + (i * ARCH_PAGE_SIZE), - ARCH_PAGE_SIZE); + if (inode) + inode->write((u8*)MMU::translate_physical_address(frames[i]), offset + (i * ARCH_PAGE_SIZE), + ARCH_PAGE_SIZE); + if (device) + device->write((u8*)MMU::translate_physical_address(frames[i]), offset + (i * ARCH_PAGE_SIZE), + ARCH_PAGE_SIZE); } }