Potential Memory Leak in proc `map_file_from_path ` from package `core:mem/virtual`

The map_file_from_path proc is useful to memory map files. On Windows it calls the MapViewOfFile to map the contents of the file to a virtual address range. But the release proc never calls the UnmapViewOfFile to unmap that address range. Instead it tries to release using the VirtualFree function. But this MSDN doc page states that VirtualFree cannot be used to free the address range when it is mapped to a file.

After a page from the reserved range is committed, it cannot be freed or decommitted by calling VirtualFree. Reserved and committed pages are released when the view is unmapped and the file mapping object is closed. For details, see the UnmapViewOfFileand CloseHandle functions.

Source https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-mapviewoffile

I want to see if this is indeed a bug or am I missing something?

Preface: I know basically nothing about virtual memory so please be critical of anything I say!

I agree with you that this is a bug according to the MS docs. There’s also an example in the docs that uses UnmapViewOfFile, not VirtualFree. I’d suggest you create a minimal reproducible code example of the bug and file an issue on Github. Does that sound good?

On the minimal code example for the bug: If I was you, I’d just use the MS example (linked above) and try that out with both VirtualFree and UnmapViewOfFile and then then in each cases access the file afterwards, which should produce some error in case the unmapping/freeing worked, otherwise there is a bug or at least undocumented behavior.