fix: memory leak

This commit is contained in:
kailixu 2023-01-13 02:12:04 +08:00
parent 707ad8f397
commit 6851a7db04
2 changed files with 18 additions and 20 deletions

View File

@ -3001,7 +3001,7 @@ int32_t tSerializeSTableIndexRsp(void *buf, int32_t bufLen, const STableIndexRsp
void tFreeSerializeSTableIndexRsp(STableIndexRsp *pRsp) { void tFreeSerializeSTableIndexRsp(STableIndexRsp *pRsp) {
if (pRsp->pIndex != NULL) { if (pRsp->pIndex != NULL) {
taosArrayDestroy(pRsp->pIndex); tFreeSTableIndexRsp(pRsp);
pRsp->pIndex = NULL; pRsp->pIndex = NULL;
} }
} }

View File

@ -256,28 +256,23 @@ int32_t smaBlockToSubmit(SVnode *pVnode, const SArray *pBlocks, const STSchema *
int32_t rows = pDataBlock->info.rows; int32_t rows = pDataBlock->info.rows;
SSubmitTbData *pTbData = (SSubmitTbData *)taosMemoryCalloc(1, sizeof(SSubmitTbData)); SSubmitTbData tbData = {0};
if (!pTbData) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto _end;
}
if (!(pTbData->aRowP = taosArrayInit(rows, sizeof(SRow *)))) { if (!(tbData.aRowP = taosArrayInit(rows, sizeof(SRow *)))) {
taosMemoryFree(pTbData);
goto _end; goto _end;
} }
pTbData->suid = suid; tbData.suid = suid;
pTbData->uid = 0; // uid is assigned by vnode tbData.uid = 0; // uid is assigned by vnode
pTbData->sver = pTSchema->version; tbData.sver = pTSchema->version;
if (createTb) { if (createTb) {
pTbData->pCreateTbReq = taosArrayGetP(createTbArray, i); tbData.pCreateTbReq = taosArrayGetP(createTbArray, i);
if (pTbData->pCreateTbReq) pTbData->flags = SUBMIT_REQ_AUTO_CREATE_TABLE; if (tbData.pCreateTbReq) tbData.flags = SUBMIT_REQ_AUTO_CREATE_TABLE;
} }
if (!pVals && !(pVals = taosArrayInit(pTSchema->numOfCols, sizeof(SColVal)))) { if (!pVals && !(pVals = taosArrayInit(pTSchema->numOfCols, sizeof(SColVal)))) {
taosArrayDestroy(pTbData->aRowP); taosArrayDestroy(tbData.aRowP);
taosMemoryFree(pTbData);
goto _end; goto _end;
} }
@ -305,14 +300,13 @@ int32_t smaBlockToSubmit(SVnode *pVnode, const SArray *pBlocks, const STSchema *
} }
SRow *pRow = NULL; SRow *pRow = NULL;
if ((terrno = tRowBuild(pVals, (STSchema *)pTSchema, &pRow)) < 0) { if ((terrno = tRowBuild(pVals, (STSchema *)pTSchema, &pRow)) < 0) {
tDestroySSubmitTbData(pTbData, TSDB_MSG_FLG_ENCODE); tDestroySSubmitTbData(&tbData, TSDB_MSG_FLG_ENCODE);
goto _end; goto _end;
} }
ASSERT(pRow); taosArrayPush(tbData.aRowP, &pRow);
taosArrayPush(pTbData->aRowP, &pRow);
} }
taosArrayPush(pReq->aSubmitTbData, pTbData); taosArrayPush(pReq->aSubmitTbData, &tbData);
} }
// encode // encode
@ -334,9 +328,13 @@ int32_t smaBlockToSubmit(SVnode *pVnode, const SArray *pBlocks, const STSchema *
tEncoderClear(&encoder); tEncoderClear(&encoder);
} }
_end: _end:
taosArrayDestroy(createTbArray);
taosArrayDestroy(tagArray); taosArrayDestroy(tagArray);
taosArrayDestroy(pVals); taosArrayDestroy(pVals);
tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE); if (pReq) {
tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
taosMemoryFree(pReq);
}
if (terrno != 0) { if (terrno != 0) {
rpcFreeCont(pBuf); rpcFreeCont(pBuf);