From 74305814f0da86baeb13d46bbfd5a35cc03d5cec Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 19 Oct 2022 13:38:01 +0800 Subject: [PATCH] fix(query): fix coverity issues. --- source/dnode/vnode/src/meta/metaQuery.c | 5 +++ source/dnode/vnode/src/tsdb/tsdbCacheRead.c | 1 + source/dnode/vnode/src/tsdb/tsdbRead.c | 6 ++++ source/libs/executor/src/executor.c | 5 +-- source/libs/executor/src/executorimpl.c | 1 + source/libs/executor/src/groupoperator.c | 9 ++++-- source/libs/executor/src/scanoperator.c | 31 +++++++++++++------ source/libs/executor/src/tfill.c | 4 ++- source/libs/executor/src/timewindowoperator.c | 17 +++++----- source/libs/executor/src/tsort.c | 3 +- 10 files changed, 60 insertions(+), 22 deletions(-) diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index 631ef09d4b..98e948481e 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -687,7 +687,12 @@ int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sv SSchema *pSchema = pSchemaWrapper->pSchema + i; tdAddColToSchema(&sb, pSchema->type, pSchema->flags, pSchema->colId, pSchema->bytes); } + STSchema *pTSchema = tdGetSchemaFromBuilder(&sb); + if (pTSchema == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + tdDestroyTSchemaBuilder(&sb); *ppTSchema = pTSchema; diff --git a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c index 81219e1442..20352bb502 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c @@ -84,6 +84,7 @@ int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList p->transferBuf = taosMemoryCalloc(p->pSchema->numOfCols, POINTER_BYTES); if (p->transferBuf == NULL) { + tsdbCacherowsReaderClose(p); return TSDB_CODE_OUT_OF_MEMORY; } diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 3f88d478e2..452e8c5d55 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -2554,6 +2554,12 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) { pScanInfo = pReader->status.pTableIter; } + if (pScanInfo == NULL) { + tsdbError("failed to get table, uid:"PRIu64 ", %s", pBlockInfo->uid, pReader->idStr); + code = TSDB_CODE_INVALID_PARA; + return code; + } + if (pBlockInfo != NULL) { pBlock = getCurrentBlock(pBlockIter); } diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index 0d861c1fb9..ba687ab7fc 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -250,6 +250,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo qDebug(" %d qualified child tables added into stream scanner", (int32_t)taosArrayGetSize(qa)); code = tqReaderAddTbUidList(pScanInfo->tqReader, qa); if (code != TSDB_CODE_SUCCESS) { + taosArrayDestroy(qa); return code; } @@ -261,6 +262,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo assignUid = groupbyTbname(pScanInfo->pGroupTags); keyBuf = taosMemoryMalloc(bufLen); if (keyBuf == NULL) { + taosArrayDestroy(qa); return TSDB_CODE_OUT_OF_MEMORY; } } @@ -277,6 +279,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo &keyInfo.groupId); if (code != TSDB_CODE_SUCCESS) { taosMemoryFree(keyBuf); + taosArrayDestroy(qa); return code; } } @@ -298,8 +301,6 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo taosHashPut(pTaskInfo->tableqinfoList.map, uid, sizeof(*uid), &keyInfo.groupId, sizeof(keyInfo.groupId)); } - /*}*/ - if (keyBuf != NULL) { taosMemoryFree(keyBuf); } diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index a7e98527f4..8e53cc2c33 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -462,6 +462,7 @@ static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunc for (int32_t i = 0; i < numOfRows; ++i) { colDataAppend(pColInfo, i, tmp, false); } + taosMemoryFree(tmp); } return TSDB_CODE_SUCCESS; diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index e62f72c8f8..4ca4ef7b3f 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -757,7 +757,6 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition goto _error; } - SSDataBlock* pResBlock = createResDataBlock(pPartNode->node.pOutputDataBlockDesc); int32_t numOfCols = 0; SExprInfo* pExprInfo = createExprInfo(pPartNode->pTargets, NULL, &numOfCols); @@ -781,14 +780,18 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition uint32_t defaultPgsz = 0; uint32_t defaultBufsz = 0; + + SSDataBlock* pResBlock = createResDataBlock(pPartNode->node.pOutputDataBlockDesc); getBufferPgSize(pResBlock->info.rowSize, &defaultPgsz, &defaultBufsz); if (!osTempSpaceAvailable()) { terrno = TSDB_CODE_NO_AVAIL_DISK; pTaskInfo->code = terrno; qError("Create partition operator info failed since %s", terrstr(terrno)); + blockDataDestroy(pResBlock); goto _error; } + int32_t code = createDiskbasedBuf(&pInfo->pBuf, defaultPgsz, defaultBufsz, pTaskInfo->id.str, tsTempDir); if (code != TSDB_CODE_SUCCESS) { goto _error; @@ -819,7 +822,9 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition _error: pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; - taosMemoryFreeClear(pInfo); + if (pInfo != NULL) { + destroyPartitionOperatorInfo(pInfo); + } taosMemoryFreeClear(pOperator); return NULL; } diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 8e1858d8c0..109e402b45 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -737,7 +737,7 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SDataBlockDescNode* pDescNode = pTableScanNode->scan.node.pOutputDataBlockDesc; int32_t numOfCols = 0; - SArray* pColList = extractColMatchInfo(pTableScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID); + pInfo->pColMatchInfo = extractColMatchInfo(pTableScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID); int32_t code = initQueryTableDataCond(&pInfo->cond, pTableScanNode); if (code != TSDB_CODE_SUCCESS) { @@ -765,7 +765,6 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, } pInfo->scanFlag = MAIN_SCAN; - pInfo->pColMatchInfo = pColList; pInfo->currentGroupId = -1; pInfo->assignBlockUid = pTableScanNode->assignBlockUid; @@ -1769,8 +1768,9 @@ FETCH_NEXT_BLOCK: generateDeleteResultBlock(pInfo, pDelBlock, pInfo->pDeleteDataRes); pInfo->pDeleteDataRes->info.type = STREAM_DELETE_RESULT; printDataBlock(pDelBlock, "stream scan delete result"); + blockDataDestroy(pDelBlock); + if (pInfo->pDeleteDataRes->info.rows > 0) { - blockDataDestroy(pDelBlock); return pInfo->pDeleteDataRes; } else { goto FETCH_NEXT_BLOCK; @@ -2091,24 +2091,30 @@ SOperatorInfo* createRawScanOperatorInfo(SReadHandle* pHandle, SExecTaskInfo* pT // create meta reader // create tq reader + int32_t code = TSDB_CODE_SUCCESS; + SStreamRawScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamRawScanInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { - terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; - return NULL; + code = TSDB_CODE_OUT_OF_MEMORY; + goto _end; } pInfo->vnode = pHandle->vnode; pInfo->sContext = pHandle->sContext; pOperator->name = "RawStreamScanOperator"; - // pOperator->blocking = false; - // pOperator->status = OP_NOT_OPENED; pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(NULL, doRawScan, NULL, NULL, destroyRawScanOperatorInfo, NULL, NULL, NULL); return pOperator; + + _end: + taosMemoryFree(pInfo); + taosMemoryFree(pOperator); + pTaskInfo->code = code; + return NULL; } static void destroyStreamScanOperatorInfo(void* param) { @@ -2286,7 +2292,14 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys return pOperator; _error: - taosMemoryFreeClear(pInfo); + if (pColIds != NULL) { + taosArrayDestroy(pColIds); + } + + if (pInfo != NULL) { + destroyStreamScanOperatorInfo(pInfo); + } + taosMemoryFreeClear(pOperator); return NULL; } @@ -3334,7 +3347,7 @@ int32_t createScanTableListInfo(SScanPhysiNode* pScanNode, SNodeList* pGroupTags int64_t st = taosGetTimestampUs(); if (pHandle == NULL) { - qError("invalid handle, in creating operator tree", idStr); + qError("invalid handle, in creating operator tree, %s", idStr); return TSDB_CODE_INVALID_PARA; } diff --git a/source/libs/executor/src/tfill.c b/source/libs/executor/src/tfill.c index 8b716531e5..f9d914d9ee 100644 --- a/source/libs/executor/src/tfill.c +++ b/source/libs/executor/src/tfill.c @@ -467,9 +467,11 @@ struct SFillInfo* taosCreateFillInfo(TSKEY skey, int32_t numOfFillCols, int32_t case FILL_MODE_VALUE: pFillInfo->type = TSDB_FILL_SET_VALUE; break; - default: + default: { + taosMemoryFree(pFillInfo); terrno = TSDB_CODE_INVALID_PARA; return NULL; + } } pFillInfo->type = fillType; diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index d99945e7a9..d149bd4a12 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -2774,14 +2774,13 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SStateWi int32_t num = 0; SExprInfo* pExprInfo = createExprInfo(pStateNode->window.pFuncs, NULL, &num); - SSDataBlock* pResBlock = createResDataBlock(pStateNode->window.node.pOutputDataBlockDesc); - initResultSizeInfo(&pOperator->resultInfo, 4096); int32_t code = initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } + SSDataBlock* pResBlock = createResDataBlock(pStateNode->window.node.pOutputDataBlockDesc); initBasicInfo(&pInfo->binfo, pResBlock); initResultRowInfo(&pInfo->binfo.resultRowInfo); @@ -2809,7 +2808,10 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SStateWi return pOperator; _error: - destroyStateWindowOperatorInfo(pInfo); + if (pInfo != NULL) { + destroyStateWindowOperatorInfo(pInfo); + } + taosMemoryFreeClear(pOperator); pTaskInfo->code = code; return NULL; @@ -5306,9 +5308,7 @@ SOperatorInfo* createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream, goto _error; } - int32_t num = 0; - SExprInfo* pExprInfo = createExprInfo(pNode->window.pFuncs, NULL, &num); - SSDataBlock* pResBlock = createResDataBlock(pNode->window.node.pOutputDataBlockDesc); + SInterval interval = {.interval = pNode->interval, .sliding = pNode->sliding, @@ -5332,11 +5332,14 @@ SOperatorInfo* createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream, size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; initResultSizeInfo(&pOperator->resultInfo, 4096); - int32_t code = initAggInfo(&pOperator->exprSupp, &iaInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str); + int32_t num = 0; + SExprInfo* pExprInfo = createExprInfo(pNode->window.pFuncs, NULL, &num); + int32_t code = initAggInfo(&pOperator->exprSupp, &iaInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } + SSDataBlock* pResBlock = createResDataBlock(pNode->window.node.pOutputDataBlockDesc); initBasicInfo(&iaInfo->binfo, pResBlock); initExecTimeWindowInfo(&iaInfo->twAggSup.timeWindowData, &iaInfo->win); diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 85582cbd39..03248f5069 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -181,6 +181,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { blockDataSplitRows(pDataBlock, pDataBlock->info.hasVarCol, start, &stop, pHandle->pageSize); SSDataBlock* p = blockDataExtractBlock(pDataBlock, start, stop - start + 1); if (p == NULL) { + taosArrayDestroy(pPageIdList); return terrno; } @@ -422,7 +423,7 @@ int32_t msortComparFn(const void* pLeft, const void* pRight, void* param) { SColumnInfoData* pRightColInfoData = TARRAY_GET_ELEM(pRightBlock->pDataBlock, pOrder->slotId); bool rightNull = false; if (pRightColInfoData->hasNull) { - if (pLeftBlock->pBlockAgg == NULL) { + if (pRightBlock->pBlockAgg == NULL) { rightNull = colDataIsNull_s(pRightColInfoData, pRightSource->src.rowIndex); } else { rightNull = colDataIsNull(pRightColInfoData, pRightBlock->info.rows, pRightSource->src.rowIndex, -- GitLab