From c590eb656f51446cbbc28a842db071bd9e277a31 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sat, 11 Apr 2020 14:52:49 +0300 Subject: [PATCH] mdbx: fix null-deref in an ASAN-enabled build while opening DB with error. More for https://github.com/erthink/libmdbx/issues/95 Change-Id: I6250fe7b0fbbcae497c2b5c1da9b4e9f78ecf0f0 --- src/elements/core.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/elements/core.c b/src/elements/core.c index afde002d..29205e1c 100644 --- a/src/elements/core.c +++ b/src/elements/core.c @@ -10148,12 +10148,13 @@ 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) { + if (rc != MDBX_SUCCESS) { rc = mdbx_env_close0(env) ? MDBX_PANIC : rc; env->me_flags = saved_me_flags | MDBX_FATAL_ERROR; + } else { +#if defined(MDBX_USE_VALGRIND) || defined(__SANITIZE_ADDRESS__) + mdbx_txn_valgrind(env, nullptr); +#endif } mdbx_free(lck_pathname); return rc;