From 29d34200b5da7b79dd3ec359f821e8eac7ddb523 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 5 Jun 2024 13:39:46 +0800 Subject: [PATCH] other: fix coverity issues. --- source/dnode/vnode/src/tsdb/tsdbRead2.c | 2 ++ source/libs/executor/src/tsort.c | 10 ++++++---- source/libs/stream/src/streamBackendRocksdb.c | 6 ------ source/libs/stream/src/streamCheckpoint.c | 13 ++++++++++--- source/libs/stream/src/streamDispatch.c | 1 + source/libs/stream/src/streamSnapshot.c | 1 + 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbRead2.c b/source/dnode/vnode/src/tsdb/tsdbRead2.c index d7c3eff571..28b7392a70 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead2.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead2.c @@ -927,6 +927,8 @@ static int32_t getEndPosInDataBlock(STsdbReader* pReader, SBlockData* pBlockData } else { int64_t key = asc ? pReader->info.window.ekey : pReader->info.window.skey; endPos = doBinarySearchKey(pBlockData->aTSKEY, pRecord->numRow, pos, key, pReader->info.order); + ASSERT(endPos > 0 && endPos < pRecord->numRow - 1); + endPos = findFirstPos(pBlockData->aTSKEY, pRecord->numRow, endPos, asc); } diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index daac98bbfc..8ab388830f 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -989,13 +989,15 @@ void tsortAppendTupleToBlock(SSortHandle* pHandle, SSDataBlock* pBlock, STupleHa colDataSetNULL(pColInfo, pBlock->info.rows); } } - if (bFreeRow) { - taosMemoryFree(buf); - } + if (*(int32_t*)pStart != pStart - buf) { qError("table merge scan row buf deserialization. length error %d != %d ", *(int32_t*)pStart, (int32_t)(pStart - buf)); - }; + } + + if (bFreeRow) { + taosMemoryFree(buf); + } pBlock->info.dataLoad = 1; pBlock->info.scanFlag = ((SDataBlockInfo*)tsortGetBlockInfo(pTupleHandle))->scanFlag; diff --git a/source/libs/stream/src/streamBackendRocksdb.c b/source/libs/stream/src/streamBackendRocksdb.c index d42a3b545a..597d6035d6 100644 --- a/source/libs/stream/src/streamBackendRocksdb.c +++ b/source/libs/stream/src/streamBackendRocksdb.c @@ -195,12 +195,6 @@ int32_t getCfIdx(const char* cfName) { bool isValidCheckpoint(const char* dir) { return true; - STaskDbWrapper* pDb = taskDbOpenImpl(NULL, NULL, (char*)dir); - if (pDb == NULL) { - return false; - } - taskDbDestroy(pDb, false); - return true; } int32_t rebuildDirFromCheckpoint(const char* path, int64_t chkpId, char** dst) { diff --git a/source/libs/stream/src/streamCheckpoint.c b/source/libs/stream/src/streamCheckpoint.c index 94d2198e31..648221890a 100644 --- a/source/libs/stream/src/streamCheckpoint.c +++ b/source/libs/stream/src/streamCheckpoint.c @@ -526,6 +526,8 @@ void streamTaskSetFailedCheckpointId(SStreamTask* pTask) { } static int32_t getCheckpointDataMeta(const char* id, const char* path, SArray* list) { + char buf[128] = {0}; + char* file = taosMemoryCalloc(1, strlen(path) + 32); sprintf(file, "%s%s%s", path, TD_DIRSEP, "META_TMP"); @@ -537,12 +539,17 @@ static int32_t getCheckpointDataMeta(const char* id, const char* path, SArray* l } TdFilePtr pFile = taosOpenFile(file, TD_FILE_READ); - char buf[128] = {0}; + if (pFile == NULL) { + stError("%s failed to open meta file:%s for checkpoint", id, file); + code = -1; + return code; + } + if (taosReadFile(pFile, buf, sizeof(buf)) <= 0) { - stError("chkp failed to read meta file:%s", file); + stError("%s failed to read meta file:%s for checkpoint", id, file); code = -1; } else { - int32_t len = strlen(buf); + int32_t len = strnlen(buf, tListLen(buf)); for (int i = 0; i < len; i++) { if (buf[i] == '\n') { char* item = taosMemoryCalloc(1, i + 1); diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index 2e776313e0..2bd024fac1 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -246,6 +246,7 @@ static int32_t doBuildDispatchMsg(SStreamTask* pTask, const SStreamDataBlock* pD int32_t downstreamTaskId = pTask->outputInfo.fixedDispatcher.taskId; code = tInitStreamDispatchReq(pReq, pTask, pData->srcVgId, numOfBlocks, downstreamTaskId, pData->type); if (code != TSDB_CODE_SUCCESS) { + taosMemoryFree(pReq); return code; } diff --git a/source/libs/stream/src/streamSnapshot.c b/source/libs/stream/src/streamSnapshot.c index 25015c4d33..adefe97f1f 100644 --- a/source/libs/stream/src/streamSnapshot.c +++ b/source/libs/stream/src/streamSnapshot.c @@ -298,6 +298,7 @@ int32_t streamSnapHandleInit(SStreamSnapHandle* pHandle, char* path, void* pMeta SArray* pSnapInfoSet = taosArrayInit(4, sizeof(SStreamTaskSnap)); int32_t code = streamCreateTaskDbSnapInfo(pMeta, path, pSnapInfoSet); if (code != 0) { + taosArrayDestroy(pSnapInfoSet); return -1; }