enh: handle memory leak when error occurs

This commit is contained in:
Hongze Cheng 2024-09-25 08:45:21 +08:00
parent ac8f72dcaf
commit 20d9befb9b
3 changed files with 15 additions and 2 deletions

View File

@ -62,7 +62,10 @@ int metaGetTableEntryByVersion(SMetaReader *pReader, int64_t version, tb_uid_t u
tDecoderInit(&pReader->coder, pReader->pBuf, pReader->szBuf); tDecoderInit(&pReader->coder, pReader->pBuf, pReader->szBuf);
code = metaDecodeEntry(&pReader->coder, &pReader->me); code = metaDecodeEntry(&pReader->coder, &pReader->me);
if (code) return code; if (code) {
tDecoderClear(&pReader->coder);
return code;
}
// taosMemoryFreeClear(pReader->me.colCmpr.pColCmpr); // taosMemoryFreeClear(pReader->me.colCmpr.pColCmpr);
return 0; return 0;
@ -393,6 +396,7 @@ _query:
tDecoderInit(&dc, pData, nData); tDecoderInit(&dc, pData, nData);
int32_t code = metaDecodeEntry(&dc, &me); int32_t code = metaDecodeEntry(&dc, &me);
if (code) { if (code) {
tDecoderClear(&dc);
goto _err; goto _err;
} }
if (me.type == TSDB_SUPER_TABLE) { if (me.type == TSDB_SUPER_TABLE) {
@ -1277,7 +1281,11 @@ int32_t metaFilterTableIds(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
tDecoderInit(&dc, pData, nData); tDecoderInit(&dc, pData, nData);
TAOS_CHECK_GOTO(metaDecodeEntry(&dc, &oStbEntry), NULL, END); code = metaDecodeEntry(&dc, &oStbEntry);
if (code) {
tDecoderClear(&dc);
goto END;
}
if (oStbEntry.stbEntry.schemaTag.pSchema == NULL || oStbEntry.stbEntry.schemaTag.pSchema == NULL) { if (oStbEntry.stbEntry.schemaTag.pSchema == NULL || oStbEntry.stbEntry.schemaTag.pSchema == NULL) {
TAOS_CHECK_GOTO(TSDB_CODE_INVALID_PARA, NULL, END); TAOS_CHECK_GOTO(TSDB_CODE_INVALID_PARA, NULL, END);

View File

@ -605,6 +605,7 @@ int32_t getTableInfoFromSnapshot(SSnapContext* ctx, void** pBuf, int32_t* contLe
tDecoderInit(&dc, pVal, vLen); tDecoderInit(&dc, pVal, vLen);
ret = metaDecodeEntry(&dc, &me); ret = metaDecodeEntry(&dc, &me);
if (ret < 0) { if (ret < 0) {
tDecoderClear(&dc);
ret = TAOS_GET_TERRNO(ret); ret = TAOS_GET_TERRNO(ret);
goto END; goto END;
} }

View File

@ -565,6 +565,7 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
if (ret < 0) { if (ret < 0) {
metaError("vgId:%d, failed to decode stb:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, metaError("vgId:%d, failed to decode stb:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name,
pReq->suid, tstrerror(ret)); pReq->suid, tstrerror(ret));
tDecoderClear(&dc);
tdbTbcClose(pTbDbc); tdbTbcClose(pTbDbc);
tdbTbcClose(pUidIdxc); tdbTbcClose(pUidIdxc);
return terrno; return terrno;
@ -1504,6 +1505,7 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p
tDecoderInit(&tdc, tData, tLen); tDecoderInit(&tdc, tData, tLen);
int32_t ret = metaDecodeEntry(&tdc, &stbEntry); int32_t ret = metaDecodeEntry(&tdc, &stbEntry);
if (ret < 0) { if (ret < 0) {
tDecoderClear(&tdc);
metaError("vgId:%d, failed to decode child table:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, metaError("vgId:%d, failed to decode child table:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name,
e.ctbEntry.suid, tstrerror(ret)); e.ctbEntry.suid, tstrerror(ret));
return ret; return ret;
@ -2399,6 +2401,7 @@ static int metaAddTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTb
tDecoderInit(&dc, pVal, nVal); tDecoderInit(&dc, pVal, nVal);
ret = metaDecodeEntry(&dc, &stbEntry); ret = metaDecodeEntry(&dc, &stbEntry);
if (ret < 0) { if (ret < 0) {
tDecoderClear(&dc);
goto _err; goto _err;
} }
@ -2540,6 +2543,7 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT
tDecoderInit(&dc, pVal, nVal); tDecoderInit(&dc, pVal, nVal);
ret = metaDecodeEntry(&dc, &stbEntry); ret = metaDecodeEntry(&dc, &stbEntry);
if (ret < 0) { if (ret < 0) {
tDecoderClear(&dc);
goto _err; goto _err;
} }