Skip to content

Commit

Permalink
kram - fix win_mmap.h
Browse files Browse the repository at this point in the history
This doesn't need to leak the file mapping.
TODO: move to https://github.com/shixiongfei/mmap-win32/blob/master/mmap.c
  • Loading branch information
alecazam committed Jun 2, 2024
1 parent 7d25846 commit 43d6d91
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions libkram/kram/win_mmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 43d6d91

Please sign in to comment.