The mmap size supported by valgrind is set at valgrind compile time. If
the application tries to mmap in total more than the supported size,
the mmap fails. As a result lmdb fails to open the DB which is
interpreted as a broken DB, thus the DB is deleted.
Valgrind can be detected at runtime using the RUNNING_ON_VALGRIND
macro from valgrind.h, which is added to the sources:
You are encouraged to copy the valgrind/*.h headers into your project's
include directory, so your program doesn't have a compile-time
dependency on Valgrind being installed. The Valgrind headers, unlike
most of the rest of the code, are under a BSD-style license so you may
include them without worrying about license incompatibility.