From 4899b155e3ba4acd8e5d156a1ac2fe49a208d15f Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sun, 9 Nov 2025 10:18:07 +0300 Subject: [PATCH] mdbx: fix tls-dtor in case library unloading with an incomplete initialized env instance (backport). --- src/tls.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tls.c b/src/tls.c index 9d8fab2f..b2915e40 100644 --- a/src/tls.c +++ b/src/tls.c @@ -513,7 +513,9 @@ __cold void rthc_dtor(const uint32_t current_pid) { MDBX_env *const env = rthc_table[i].env; if (env->pid != current_pid) continue; - if (!(env->flags & ENV_TXKEY)) + if (!env->lck_mmap.lck || env->lck_mmap.base == MAP_FAILED) + continue; + if (!(env->flags & ENV_TXKEY) || !env->lck_mmap.lck) continue; env->flags -= ENV_TXKEY; reader_slot_t *const begin = &env->lck_mmap.lck->rdt[0];