From d5f140aee2177b762901436bc421698c3381daef Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Mon, 29 Apr 2024 15:23:00 +0800 Subject: [PATCH 1/2] fix(tdb/btc): free txn early when closing btc --- source/libs/tdb/src/db/tdbBtree.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 7a62b38b16..543e06aae6 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -2473,6 +2473,10 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { } int tdbBtcClose(SBTC *pBtc) { + if (pBtc->freeTxn) { + tdbTxnClose(pBtc->pTxn); + } + if (pBtc->iPage < 0) return 0; for (;;) { @@ -2496,10 +2500,6 @@ int tdbBtcClose(SBTC *pBtc) { tdbFree(pBtc->coder.pVal); } - if (pBtc->freeTxn) { - tdbTxnClose(pBtc->pTxn); - } - return 0; } From 785faf50aaf3f6f6566721fb9e7b95d8b95e2684 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Mon, 29 Apr 2024 16:27:11 +0800 Subject: [PATCH 2/2] btc/close: free txn only if iPage < 0 --- source/libs/tdb/src/db/tdbBtree.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 543e06aae6..26652cfffb 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -2473,12 +2473,13 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { } int tdbBtcClose(SBTC *pBtc) { - if (pBtc->freeTxn) { - tdbTxnClose(pBtc->pTxn); + if (pBtc->iPage < 0) { + if (pBtc->freeTxn) { + tdbTxnClose(pBtc->pTxn); + } + return 0; } - if (pBtc->iPage < 0) return 0; - for (;;) { if (NULL == pBtc->pPage) { tdbError("tdb/btc-close: null ptr pPage."); @@ -2500,6 +2501,10 @@ int tdbBtcClose(SBTC *pBtc) { tdbFree(pBtc->coder.pVal); } + if (pBtc->freeTxn) { + tdbTxnClose(pBtc->pTxn); + } + return 0; }