From 23d2f0fbb5c7f4de2c12824af95da387fffc39d4 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sat, 13 Oct 2018 12:02:17 +0300 Subject: [PATCH] mdbx: avoid on-stack allocation/chkstk inside mdbx_kill_page(). 3 of 17 for https://github.com/leo-yuriev/libmdbx/issues/43 Change-Id: Icff2d67f84283820fb21932c0d439d645c634d25 --- src/mdbx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mdbx.c b/src/mdbx.c index c8ee774d..1e355e58 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -1663,7 +1663,9 @@ static size_t bytes_align2os_bytes(const MDBX_env *env, size_t bytes) { static void __cold mdbx_kill_page(MDBX_env *env, MDBX_page *mp) { const size_t len = env->me_psize - PAGEHDRSZ; - void *ptr = (env->me_flags & MDBX_WRITEMAP) ? &mp->mp_data : alloca(len); + void *ptr = (env->me_flags & MDBX_WRITEMAP) + ? &mp->mp_data + : (void *)((uint8_t *)env->me_pbuf + env->me_psize); memset(ptr, 0x6F /* 'o', 111 */, len); if (ptr != &mp->mp_data) (void)mdbx_pwrite(env->me_fd, ptr, len, @@ -6474,7 +6476,7 @@ int __cold mdbx_env_open(MDBX_env *env, const char *path, unsigned flags, size = tsize + env->me_maxdbs * (sizeof(MDBX_db) + sizeof(MDBX_cursor *) + sizeof(unsigned) + 1); - if ((env->me_pbuf = mdbx_calloc(1, env->me_psize)) && + if ((env->me_pbuf = mdbx_calloc(2, env->me_psize)) && (txn = mdbx_calloc(1, size))) { txn->mt_dbs = (MDBX_db *)((char *)txn + tsize); txn->mt_cursors = (MDBX_cursor **)(txn->mt_dbs + env->me_maxdbs);