mdbx: fix ASAN issues (minor).

This resolves https://github.com/leo-yuriev/libmdbx/issues/73

Change-Id: Ifb59f5ba66321bb362b81085e0f25a82a2d76d5f
This commit is contained in:
Leonid Yuriev 2019-12-29 01:19:31 +03:00
parent b3a5ab692b
commit 8c7cdfdc79
3 changed files with 11 additions and 4 deletions

View File

@ -4883,7 +4883,7 @@ static void mdbx_txn_valgrind(MDBX_env *env, MDBX_txn *txn) {
mdbx_txn_unlock(env);
}
}
#endif /* MDBX_USE_VALGRIND */
#endif /* MDBX_USE_VALGRIND || __SANITIZE_ADDRESS__ */
/* Common code for mdbx_txn_begin() and mdbx_txn_renew(). */
static int mdbx_txn_renew0(MDBX_txn *txn, unsigned flags) {
@ -7464,7 +7464,7 @@ static int mdbx_sync_locked(MDBX_env *env, unsigned flags,
ASAN_POISON_MEMORY_REGION(env->me_map + pgno2bytes(env, largest_pgno),
pgno2bytes(env, edge - largest_pgno));
}
#endif /* MDBX_USE_VALGRIND */
#endif /* MDBX_USE_VALGRIND || __SANITIZE_ADDRESS__ */
#if defined(MADV_DONTNEED)
const size_t largest_bytes = pgno2bytes(env, largest_pgno);
const size_t madvise_gap = (largest_bytes < 65536 * 256)
@ -8420,7 +8420,7 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, const int lck_rc) {
ASAN_POISON_MEMORY_REGION(env->me_map + used_bytes,
env->me_dxb_mmap.limit - used_bytes);
env->me_poison_edge = bytes2pgno(env, env->me_dxb_mmap.limit);
#endif /* MDBX_USE_VALGRIND */
#endif /* MDBX_USE_VALGRIND || __SANITIZE_ADDRESS__ */
/* NOTE: AddressSanitizer (at least GCC 7.x, 8.x) could generate
* false-positive alarm here. I have no other explanation for this
@ -9213,6 +9213,9 @@ int __cold mdbx_env_open(MDBX_env *env, const char *pathname, unsigned flags,
#endif
bailout:
#if defined(MDBX_USE_VALGRIND) || defined(__SANITIZE_ADDRESS__)
mdbx_txn_valgrind(env, nullptr);
#endif
if (rc) {
rc = mdbx_env_close0(env) ? MDBX_PANIC : rc;
env->me_flags = saved_me_flags | MDBX_FATAL_ERROR;

View File

@ -949,7 +949,7 @@ struct MDBX_env {
#endif
#if defined(MDBX_USE_VALGRIND) || defined(__SANITIZE_ADDRESS__)
pgno_t me_poison_edge;
#endif
#endif /* MDBX_USE_VALGRIND || __SANITIZE_ADDRESS__ */
MDBX_env *me_lcklist_next;
/* struct me_dbgeo used for accepting db-geo params from user for the new

View File

@ -1378,10 +1378,14 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
#endif
VALGRIND_MAKE_MEM_DEFINED(map->address, map->current);
ASAN_UNPOISON_MEMORY_REGION(map->address, map->current);
return MDBX_SUCCESS;
}
MDBX_INTERNAL_FUNC int mdbx_munmap(mdbx_mmap_t *map) {
VALGRIND_MAKE_MEM_NOACCESS(map->address, map->current);
ASAN_POISON_MEMORY_REGION(map->address, map->current);
#if defined(_WIN32) || defined(_WIN64)
if (map->section)
NtClose(map->section);