From 0a62868d5ee8e1b0d637209fd9b617adb3f9da8e Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 30 Mar 2022 10:07:38 +0000 Subject: [PATCH] refact more --- source/libs/tdb/src/db/tdbBtree.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 848500875d..a4ca75ff36 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -216,15 +216,22 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen SBTC btc; SCell *pCell; int cret; + int ret; void *pVal; SCellDecoder cd; tdbBtcOpen(&btc, pBt); - tdbBtcMoveTo(&btc, pKey, kLen, &cret); + ret = tdbBtcMoveTo(&btc, pKey, kLen, &cret); + if (ret < 0) { + tdbBtcClose(&btc); + ASSERT(0); + return -1; + } if (cret) { - return cret; + tdbBtcClose(&btc); + return -1; } pCell = tdbPageGetCell(btc.pPage, btc.idx); @@ -233,11 +240,15 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen *vLen = cd.vLen; pVal = TDB_REALLOC(*ppVal, *vLen); if (pVal == NULL) { + tdbBtcClose(&btc); return -1; } *ppVal = pVal; memcpy(*ppVal, cd.pVal, cd.vLen); + + tdbBtcClose(&btc); + return 0; } -- GitLab