From 797722a6ae0fcbec60ee418b8442712f999b1dc9 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Thu, 23 Feb 2023 15:43:34 +0800 Subject: [PATCH] fix(tdb/coder): free key memory of stack btc's coder --- source/libs/tdb/src/db/tdbBtree.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index a35e01c7aa..6353d8ba27 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -264,7 +264,10 @@ int tdbBtreeUpsert(SBTree *pBt, const void *pKey, int nKey, const void *pData, i // move the cursor ret = tdbBtcMoveTo(&btc, pKey, nKey, &c); if (ret < 0) { - ASSERT(0); + tdbError("tdb/btree-upsert: btc move to failed with ret: %d.", ret); + if (TDB_CELLDECODER_FREE_KEY(&btc.coder)) { + tdbFree(btc.coder.pKey); + } tdbBtcClose(&btc); return -1; } @@ -280,11 +283,17 @@ int tdbBtreeUpsert(SBTree *pBt, const void *pKey, int nKey, const void *pData, i ret = tdbBtcUpsert(&btc, pKey, nKey, pData, nData, c); if (ret < 0) { - ASSERT(0); + if (TDB_CELLDECODER_FREE_KEY(&btc.coder)) { + tdbFree(btc.coder.pKey); + } tdbBtcClose(&btc); + tdbError("tdb/btree-upsert: btc upsert failed with ret: %d.", ret); return -1; } + if (TDB_CELLDECODER_FREE_KEY(&btc.coder)) { + tdbFree(btc.coder.pKey); + } tdbBtcClose(&btc); return 0; } @@ -2188,10 +2197,6 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { } else { lidx = lidx + 1; } - if (TDB_CELLDECODER_FREE_KEY(&pBtc->coder)) { - tdbFree((void*)pTKey); - } - // compare last cell if (lidx <= ridx) { pBtc->idx = ridx; @@ -2202,9 +2207,6 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { } else { ridx = ridx - 1; } - if (TDB_CELLDECODER_FREE_KEY(&pBtc->coder)) { - tdbFree((void*)pTKey); - } } // binary search @@ -2215,9 +2217,6 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { pBtc->idx = (lidx + ridx) >> 1; tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL); c = pBt->kcmpr(pKey, kLen, pTKey, tkLen); - if (TDB_CELLDECODER_FREE_KEY(&pBtc->coder)) { - tdbFree((void*)pTKey); - } if (c < 0) { // pKey < cd.pKey ridx = pBtc->idx - 1;