From 799f61c2dbbaa2f0961c09f7358629b0c16910c9 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 4 Jul 2024 19:20:07 +0800 Subject: [PATCH] other: fix coverity issue. --- source/libs/executor/src/scanoperator.c | 4 ++++ source/libs/stream/src/streamBackendRocksdb.c | 13 ++++++++----- source/libs/stream/src/streamSnapshot.c | 12 +++++------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 6c512d4859..490f6b86fa 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -3459,11 +3459,15 @@ static int32_t tagScanFilterByTagCond(SArray* aUidTags, SNode* pTagCond, SArray* SScalarParam output = {0}; code = tagScanCreateResultData(&type, numOfTables, &output); if (TSDB_CODE_SUCCESS != code) { + blockDataDestroy(pResBlock); + taosArrayDestroy(pBlockList); return code; } code = scalarCalculate(pTagCond, pBlockList, &output); if (TSDB_CODE_SUCCESS != code) { + blockDataDestroy(pResBlock); + taosArrayDestroy(pBlockList); return code; } diff --git a/source/libs/stream/src/streamBackendRocksdb.c b/source/libs/stream/src/streamBackendRocksdb.c index cf7852cddb..4f07faad25 100644 --- a/source/libs/stream/src/streamBackendRocksdb.c +++ b/source/libs/stream/src/streamBackendRocksdb.c @@ -238,6 +238,9 @@ int32_t remoteChkp_readMetaData(char* path, SArray* list) { sprintf(metaPath, "%s%s%s", path, TD_DIRSEP, "META"); TdFilePtr pFile = taosOpenFile(path, TD_FILE_READ); + if (pFile == NULL) { + return -1; + } char buf[128] = {0}; if (taosReadFile(pFile, buf, sizeof(buf)) <= 0) { @@ -245,7 +248,8 @@ int32_t remoteChkp_readMetaData(char* path, SArray* list) { taosCloseFile(&pFile); return -1; } - 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); @@ -2117,9 +2121,7 @@ void taskDbDestroy(void* pDb, bool flush) { stDebug("succ to destroy stream backend:%p", wrapper); - int8_t nCf = sizeof(ginitDict) / sizeof(ginitDict[0]); - - if (wrapper == NULL) return; + int8_t nCf = tListLen(ginitDict); if (flush) { if (wrapper->db && wrapper->pCf) { @@ -4223,7 +4225,8 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { static char* chkpMeta = "META"; memset(dstBuf, 0, len); - sprintf(dstDir, "%s%s%s", dstDir, TD_DIRSEP, chkpMeta); + sprintf(dstBuf, "%s%s%s", dstDir, TD_DIRSEP, chkpMeta); + tstrncpy(dstDir, dstBuf, strlen(dstBuf) + 1); TdFilePtr pFile = taosOpenFile(dstDir, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { diff --git a/source/libs/stream/src/streamSnapshot.c b/source/libs/stream/src/streamSnapshot.c index adefe97f1f..0871ff5eb7 100644 --- a/source/libs/stream/src/streamSnapshot.c +++ b/source/libs/stream/src/streamSnapshot.c @@ -312,17 +312,12 @@ int32_t streamSnapHandleInit(SStreamSnapHandle* pHandle, char* path, void* pMeta ASSERT(code == 0); taosArrayPush(pDbSnapSet, &snapFile); } + pHandle->pDbSnapSet = pDbSnapSet; pHandle->pSnapInfoSet = pSnapInfoSet; pHandle->currIdx = 0; pHandle->pMeta = pMeta; return 0; - -_err: - streamSnapHandleDestroy(pHandle); - - code = -1; - return code; } void streamSnapHandleDestroy(SStreamSnapHandle* handle) { @@ -444,6 +439,7 @@ _NEXT: pSnapFile = taosArrayGet(pHandle->pDbSnapSet, pHandle->currIdx); goto _NEXT; } else { + taosMemoryFree(buf); *ppData = NULL; *size = 0; return 0; @@ -465,7 +461,9 @@ _NEXT: pHdr->totalSize = item->size; pHdr->snapInfo = pSnapFile->snapInfo; - memcpy(pHdr->name, item->name, strlen(item->name)); + int32_t len = TMIN(strlen(item->name), tListLen(pHdr->name)); + memcpy(pHdr->name, item->name, len); + pSnapFile->seraial += nread; *ppData = buf;