From 05958a708edd2968ecfd230b2e144c4830fab435 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sun, 20 Dec 2020 16:08:57 +0300 Subject: [PATCH] mdbx: fix minor/potential mem-page leak inside `mdbx_page_unspill()`. Change-Id: I4398a4d81eda494e4de9d62d81e3936c6357b744 --- src/core.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core.c b/src/core.c index 867e2ef1..c3792118 100644 --- a/src/core.c +++ b/src/core.c @@ -5652,7 +5652,7 @@ static int __must_check_result mdbx_page_unspill(MDBX_txn *txn, MDBX_page *mp, txn->tw.dirtylist->length); return MDBX_TXN_FULL; } - unsigned num = IS_OVERFLOW(mp) ? mp->mp_pages : 1; + const unsigned num = IS_OVERFLOW(mp) ? mp->mp_pages : 1; MDBX_page *np = mp; if ((env->me_flags & MDBX_WRITEMAP) == 0) { np = mdbx_page_malloc(txn, num); @@ -5676,9 +5676,12 @@ static int __must_check_result mdbx_page_unspill(MDBX_txn *txn, MDBX_page *mp, * page remains spilled until child commits */ int rc = mdbx_page_dirty(txn, np); - if (likely(rc == MDBX_SUCCESS)) - *ret = np; - return rc; + if (unlikely(rc != MDBX_SUCCESS)) { + if ((env->me_flags & MDBX_WRITEMAP) == 0) + mdbx_dpage_free(env, np, num); + return rc; + } + *ret = np; } return MDBX_SUCCESS; }