From 8d4b6b187f58c265515d26cec33a8619ba86dbf1 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sun, 14 Jan 2018 21:02:08 +0300 Subject: [PATCH] mdbx-windows: resize file on umnap. Change-Id: Ia4739bfcd2cc7b91c14e294c7569cbee582165b1 --- src/osal.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/osal.c b/src/osal.c index 2b5791e4..f9580408 100644 --- a/src/osal.c +++ b/src/osal.c @@ -863,7 +863,7 @@ int mdbx_mmap(int flags, mdbx_mmap_t *map, size_t size, size_t limit) { if (rc == MDBX_SUCCESS) map->filesize = size; /* ignore error, because Windows unable shrink file - * that already mapped (by another process) */; + * that already mapped (by another process) */ } LARGE_INTEGER SectionSize; @@ -924,6 +924,12 @@ int mdbx_munmap(mdbx_mmap_t *map) { NTSTATUS rc = NtUnmapViewOfSection(GetCurrentProcess(), map->address); if (!NT_SUCCESS(rc)) ntstatus2errcode(rc); + + if (map->filesize != map->current && + mdbx_filesize(map->fd, &map->filesize) == MDBX_SUCCESS && + map->filesize != map->current) + (void)mdbx_ftruncate(map->fd, map->current); + map->length = 0; map->current = 0; map->address = nullptr; @@ -1019,7 +1025,7 @@ retry_file_and_section: if (err == MDBX_SUCCESS) map->filesize = size; /* ignore error, because Windows unable shrink file - * that already mapped (by another process) */; + * that already mapped (by another process) */ } SectionSize.QuadPart = size;