Skip to content

Commit f3d3f60

Browse files
committed
Try to avoid an invalid datafile after failed init
1 parent aa10c98 commit f3d3f60

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

libraries/liblmdb/mdb.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4008,6 +4008,20 @@ mdb_env_open2(MDB_env *env)
40084008
}
40094009
meta.mm_mapsize = env->me_mapsize;
40104010

4011+
if (newenv && !(flags & MDB_FIXEDMAP)) {
4012+
/* mdb_env_map() may grow the datafile. Write the metapages
4013+
* first, so the file will be valid if initialization fails.
4014+
* Except with FIXEDMAP, since we do not yet know mm_address.
4015+
* We could fill in mm_address later, but then a different
4016+
* program might end up doing that - one with a memory layout
4017+
* and map address which does not suit the main program.
4018+
*/
4019+
rc = mdb_env_init_meta(env, &meta);
4020+
if (rc)
4021+
return rc;
4022+
newenv = 0;
4023+
}
4024+
40114025
rc = mdb_env_map(env, (flags & MDB_FIXEDMAP) ? meta.mm_address : NULL);
40124026
if (rc)
40134027
return rc;

0 commit comments

Comments
 (0)