diff --git a/mdb.c b/mdb.c index 8ad6ef35..e2214db9 100644 --- a/mdb.c +++ b/mdb.c @@ -4097,6 +4097,7 @@ mdb_env_sync0(MDB_env *env, unsigned flags, MDB_meta *pending) size_t prev_mapsize = head->mm_mapsize; MDB_meta* tail = META_IS_WEAK(head) ? head : mdb_env_meta_flipflop(env, head); off_t offset = (char*) tail - env->me_map; + size_t used_size = env->me_psize * (pending->mm_last_pg + 1); mdb_assert(env, (env->me_flags & (MDB_RDONLY | MDB_FATAL_ERROR)) == 0); mdb_assert(env, META_IS_WEAK(head) || env->me_sync_pending != 0 @@ -4108,6 +4109,7 @@ mdb_env_sync0(MDB_env *env, unsigned flags, MDB_meta *pending) mdb_assert(env, pending->mm_txnid > stay->mm_txnid); pending->mm_mapsize = env->me_mapsize; + mdb_assert(env, pending->mm_mapsize >= used_size); if (unlikely(pending->mm_mapsize != prev_mapsize)) { if (pending->mm_mapsize < prev_mapsize) { /* LY: currently this can't happen, but force full-sync. */ @@ -4124,7 +4126,7 @@ mdb_env_sync0(MDB_env *env, unsigned flags, MDB_meta *pending) if (env->me_sync_pending && (flags & MDB_NOSYNC) == 0) { if (env->me_flags & MDB_WRITEMAP) { int mode = (flags & MDB_MAPASYNC) ? MS_ASYNC : MS_SYNC; - if (unlikely(msync(env->me_map, pending->mm_mapsize, mode))) { + if (unlikely(msync(env->me_map, used_size, mode))) { rc = errno; goto fail; }