From 43d6d9114848dc74b38d2463eef7d016c1bacb85 Mon Sep 17 00:00:00 2001 From: Alec Miller Date: Sat, 1 Jun 2024 21:31:03 -0700 Subject: [PATCH] kram - fix win_mmap.h This doesn't need to leak the file mapping. TODO: move to https://github.com/shixiongfei/mmap-win32/blob/master/mmap.c --- libkram/kram/win_mmap.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/libkram/kram/win_mmap.h b/libkram/kram/win_mmap.h index 68511b28..d05c8d11 100644 --- a/libkram/kram/win_mmap.h +++ b/libkram/kram/win_mmap.h @@ -83,23 +83,20 @@ static void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t if (flags & MAP_PRIVATE) dwDesiredAccess |= FILE_MAP_COPY; void *ret = MapViewOfFile(h, dwDesiredAccess, DWORD_HI(offset), DWORD_LO(offset), length); + + // can free the file mapping, mmap will hold it + CloseHandle(h); + if (ret == NULL) { - CloseHandle(h); ret = MAP_FAILED; } - // TODO: can CreateFileMapping handle be closed here? View will keep file open. - // even if the file handle (fd) is closed. That would prevent handle leak? - return ret; } static void munmap(void *addr, size_t length) { UnmapViewOfFile(addr); - - // Is this a TODO? - /* ruh-ro, we leaked handle from CreateFileMapping() ... */ } #undef DWORD_HI