From 1f7f3af16ce238f736fd5e99778780ebdc24da58 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Wed, 26 Jul 2017 12:16:47 +0300 Subject: [PATCH] mdbx: minor refine mdbx_mmap(). Change-Id: Ic5026b6412ca93a00faeb8306975d896d85b475d --- src/mdbx.c | 8 ++------ src/osal.c | 7 ++++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/mdbx.c b/src/mdbx.c index 30ec16fb..117491eb 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -4189,10 +4189,8 @@ bailout: static int __cold mdbx_env_map(MDBX_env *env, size_t usedsize) { int rc = mdbx_mmap(env->me_flags, &env->me_dxb_mmap, env->me_dbgeo.now, env->me_dbgeo.upper); - if (unlikely(rc != MDBX_SUCCESS)) { - env->me_map = NULL; + if (unlikely(rc != MDBX_SUCCESS)) return rc; - } #ifdef MADV_DONTFORK if (madvise(env->me_map, env->me_mapsize, MADV_DONTFORK)) @@ -5125,10 +5123,8 @@ static void __cold mdbx_env_close0(MDBX_env *env) { env->me_fd = INVALID_HANDLE_VALUE; } - if (env->me_lck) { + if (env->me_lck) mdbx_munmap(&env->me_lck_mmap); - env->me_lck = nullptr; - } env->me_pid = 0; env->me_oldest = nullptr; diff --git a/src/osal.c b/src/osal.c index 8595dec7..c4ecbd37 100644 --- a/src/osal.c +++ b/src/osal.c @@ -781,7 +781,7 @@ int mdbx_mmap(int flags, mdbx_mmap_t *map, size_t must, size_t limit) { map->length = 0; map->current = 0; map->section = NULL; - map->address = MAP_FAILED; + map->address = nullptr; if (GetFileType(map->fd) != FILE_TYPE_DISK) return ERROR_FILE_OFFLINE; @@ -874,7 +874,7 @@ int mdbx_mmap(int flags, mdbx_mmap_t *map, size_t must, size_t limit) { if (!NT_SUCCESS(rc)) return ntstatus2errcode(rc); - map->address = NULL; + map->address = nullptr; SIZE_T ViewSize = (flags & MDBX_RDONLY) ? must : limit; rc = NtMapViewOfSection( map->section, GetCurrentProcess(), &map->address, @@ -889,7 +889,7 @@ int mdbx_mmap(int flags, mdbx_mmap_t *map, size_t must, size_t limit) { if (!NT_SUCCESS(rc)) { NtClose(map->section); map->section = 0; - map->address = MAP_FAILED; + map->address = nullptr; return ntstatus2errcode(rc); } @@ -907,6 +907,7 @@ int mdbx_mmap(int flags, mdbx_mmap_t *map, size_t must, size_t limit) { return MDBX_SUCCESS; } map->length = 0; + map->address = nullptr; return errno; #endif }