From 4e0d69c6b00df7175501742089e7d886e5483eee Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Tue, 21 Feb 2023 16:11:14 +0800 Subject: [PATCH] fix: memory leak in tdb --- source/libs/tdb/src/db/tdbBtree.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 4f0682a617..a35e01c7aa 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -2188,6 +2188,9 @@ 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) { @@ -2199,6 +2202,9 @@ 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 @@ -2209,6 +2215,9 @@ 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; -- GitLab