]> git.sur5r.net Git - openldap/commitdiff
Fix mdb_env_set_mapsize()
authorHoward Chu <hyc@symas.com>
Fri, 4 Oct 2013 09:55:34 +0000 (02:55 -0700)
committerHoward Chu <hyc@symas.com>
Fri, 4 Oct 2013 09:55:34 +0000 (02:55 -0700)
Don't allow shrinking below minimum size for an already open env.

libraries/liblmdb/mdb.c

index 0aae74061405a173fd7ea9d437a5e79b46993ee5..ddde69d0b01745020ea5b610cc51510c31e7352c 100644 (file)
@@ -3319,6 +3319,14 @@ mdb_env_set_mapsize(MDB_env *env, size_t size)
                        return EINVAL;
                if (!size)
                        size = env->me_metas[mdb_env_pick_meta(env)]->mm_mapsize;
+               else if (size < env->me_mapsize) {
+                       /* If the configured size is smaller, make sure it's
+                        * still big enough. Silently round up to minimum if not.
+                        */
+                       size_t minsize = (env->me_metas[mdb_env_pick_meta(env)]->mm_last_pg + 1) * env->me_psize;
+                       if (size < minsize)
+                               size = minsize;
+               }
                munmap(env->me_map, env->me_mapsize);
                env->me_mapsize = size;
                old = (env->me_flags & MDB_FIXEDMAP) ? env->me_map : NULL;