未验证 提交 7461e2d2 编写于 作者: X Xiaoyu Wang 提交者: GitHub

Merge pull request #20125 from taosdata/fix/TD-22658

fix(tdb/coder): free key memory of stack btc's coder
......@@ -253,7 +253,7 @@ int tdbBtreeDelete(SBTree *pBt, const void *pKey, int kLen, TXN *pTxn) {
}
int tdbBtreeUpsert(SBTree *pBt, const void *pKey, int nKey, const void *pData, int nData, TXN *pTxn) {
SBTC btc;
SBTC btc = {0};
int c;
int ret;
......@@ -264,11 +264,18 @@ 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;
}
if (TDB_CELLDECODER_FREE_KEY(&btc.coder)) {
tdbFree(btc.coder.pKey);
}
if (btc.idx == -1) {
btc.idx = 0;
c = 1;
......@@ -280,8 +287,8 @@ 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);
tdbBtcClose(&btc);
tdbError("tdb/btree-upsert: btc upsert failed with ret: %d.", ret);
return -1;
}
......@@ -1428,15 +1435,19 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD
// Clear the state of decoder
if (TDB_CELLDECODER_FREE_VAL(pDecoder)) {
tdbFree(pDecoder->pVal);
TDB_CELLDECODER_CLZ_FREE_VAL(pDecoder);
// tdbTrace("tdb btc decoder val set nil: %p/0x%x ", pDecoder, pDecoder->freeKV);
}
if (TDB_CELLDECODER_FREE_KEY(pDecoder)) {
tdbFree(pDecoder->pKey);
TDB_CELLDECODER_CLZ_FREE_KEY(pDecoder);
// tdbTrace("tdb btc decoder key set nil: %p/0x%x ", pDecoder, pDecoder->freeKV);
}
pDecoder->kLen = -1;
pDecoder->pKey = NULL;
pDecoder->vLen = -1;
pDecoder->pVal = NULL;
pDecoder->pgno = 0;
TDB_CELLDECODER_SET_FREE_NIL(pDecoder);
// tdbTrace("tdb btc decoder set nil: %p/0x%x ", pDecoder, pDecoder->freeKV);
// 1. Decode header part
if (!leaf) {
......@@ -2188,10 +2199,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 +2209,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 +2219,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;
......
......@@ -122,6 +122,8 @@ typedef struct SBtInfo {
#define TDB_CELLD_F_VAL 0x2
#define TDB_CELLDECODER_SET_FREE_NIL(pCellDecoder) ((pCellDecoder)->freeKV = TDB_CELLD_F_NIL)
#define TDB_CELLDECODER_CLZ_FREE_KEY(pCellDecoder) ((pCellDecoder)->freeKV &= ~TDB_CELLD_F_KEY)
#define TDB_CELLDECODER_CLZ_FREE_VAL(pCellDecoder) ((pCellDecoder)->freeKV &= ~TDB_CELLD_F_VAL)
#define TDB_CELLDECODER_SET_FREE_KEY(pCellDecoder) ((pCellDecoder)->freeKV |= TDB_CELLD_F_KEY)
#define TDB_CELLDECODER_SET_FREE_VAL(pCellDecoder) ((pCellDecoder)->freeKV |= TDB_CELLD_F_VAL)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册