未验证 提交 b541ece4 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #2454 from taosdata/hotfix/coverity_query_issue

coverity issue
...@@ -767,6 +767,9 @@ static void* getDataBlockImpl(SArray* pDataBlock, int32_t colId) { ...@@ -767,6 +767,9 @@ static void* getDataBlockImpl(SArray* pDataBlock, int32_t colId) {
static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas, int32_t col, int32_t size, static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas, int32_t col, int32_t size,
SArray *pDataBlock) { SArray *pDataBlock) {
if (pDataBlock == NULL) {
return NULL;
}
char *dataBlock = NULL; char *dataBlock = NULL;
SQuery *pQuery = pRuntimeEnv->pQuery; SQuery *pQuery = pRuntimeEnv->pQuery;
...@@ -854,6 +857,7 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis * ...@@ -854,6 +857,7 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
STimeWindow win = getActiveTimeWindow(pWindowResInfo, ts, pQuery); STimeWindow win = getActiveTimeWindow(pWindowResInfo, ts, pQuery);
if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo->tid, &win) != TSDB_CODE_SUCCESS) { if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo->tid, &win) != TSDB_CODE_SUCCESS) {
tfree(sasArray);
return; return;
} }
...@@ -1349,10 +1353,13 @@ static void setCtxTagColumnInfo(SQuery *pQuery, SQLFunctionCtx *pCtx) { ...@@ -1349,10 +1353,13 @@ static void setCtxTagColumnInfo(SQuery *pQuery, SQLFunctionCtx *pCtx) {
// the column may be the normal column, group by normal_column, the functionId is TSDB_FUNC_PRJ // the column may be the normal column, group by normal_column, the functionId is TSDB_FUNC_PRJ
} }
} }
if (p != NULL) {
p->tagInfo.pTagCtxList = pTagCtx; p->tagInfo.pTagCtxList = pTagCtx;
p->tagInfo.numOfTagCols = num; p->tagInfo.numOfTagCols = num;
p->tagInfo.tagsLen = tagLen; p->tagInfo.tagsLen = tagLen;
} else {
tfree(pTagCtx);
}
} }
} }
...@@ -3497,7 +3504,7 @@ static int32_t doCopyToSData(SQInfo *pQInfo, SWindowResult *result, int32_t orde ...@@ -3497,7 +3504,7 @@ static int32_t doCopyToSData(SQInfo *pQInfo, SWindowResult *result, int32_t orde
continue; continue;
} }
assert(result[i].numOfRows >= 0 && pQInfo->offset <= 1); assert(pQInfo->offset <= 1);
int32_t numOfRowsToCopy = result[i].numOfRows - pQInfo->offset; int32_t numOfRowsToCopy = result[i].numOfRows - pQInfo->offset;
int32_t oldOffset = pQInfo->offset; int32_t oldOffset = pQInfo->offset;
...@@ -5295,9 +5302,9 @@ static int32_t createQFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo * ...@@ -5295,9 +5302,9 @@ static int32_t createQFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo *
bytes = s.bytes; bytes = s.bytes;
} else{ } else{
int32_t j = getColumnIndexInSource(pQueryMsg, &pExprs[i].base, pTagCols); int32_t j = getColumnIndexInSource(pQueryMsg, &pExprs[i].base, pTagCols);
assert(j < pQueryMsg->numOfCols || j < pQueryMsg->numOfTags || j == TSDB_TBNAME_COLUMN_INDEX); assert(j < pQueryMsg->numOfCols || j < pQueryMsg->numOfTags);
if (pExprs[i].base.colInfo.colId != TSDB_TBNAME_COLUMN_INDEX) { if (pExprs[i].base.colInfo.colId != TSDB_TBNAME_COLUMN_INDEX && j >= 0) {
SColumnInfo* pCol = (TSDB_COL_IS_TAG(pExprs[i].base.colInfo.flag))? &pTagCols[j]:&pQueryMsg->colList[j]; SColumnInfo* pCol = (TSDB_COL_IS_TAG(pExprs[i].base.colInfo.flag))? &pTagCols[j]:&pQueryMsg->colList[j];
type = pCol->type; type = pCol->type;
bytes = pCol->bytes; bytes = pCol->bytes;
...@@ -5339,8 +5346,6 @@ static int32_t createQFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo * ...@@ -5339,8 +5346,6 @@ static int32_t createQFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo *
assert(ret == TSDB_CODE_SUCCESS); assert(ret == TSDB_CODE_SUCCESS);
} }
} }
tfree(pExprMsg);
*pExprInfo = pExprs; *pExprInfo = pExprs;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -5591,11 +5596,14 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList, ...@@ -5591,11 +5596,14 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList,
pQInfo->signature = pQInfo; pQInfo->signature = pQInfo;
pQInfo->tableGroupInfo = *pTableGroupInfo; pQInfo->tableGroupInfo = *pTableGroupInfo;
size_t numOfGroups = taosArrayGetSize(pTableGroupInfo->pGroupList); size_t numOfGroups = 0;
if (pTableGroupInfo->pGroupList != NULL) {
numOfGroups = taosArrayGetSize(pTableGroupInfo->pGroupList);
pQInfo->tableqinfoGroupInfo.pGroupList = taosArrayInit(numOfGroups, POINTER_BYTES);
pQInfo->tableqinfoGroupInfo.numOfTables = pTableGroupInfo->numOfTables;
}
pQInfo->tableqinfoGroupInfo.pGroupList = taosArrayInit(numOfGroups, POINTER_BYTES);
pQInfo->tableqinfoGroupInfo.numOfTables = pTableGroupInfo->numOfTables;
int tableIndex = 0; int tableIndex = 0;
STimeWindow window = pQueryMsg->window; STimeWindow window = pQueryMsg->window;
taosArraySort(pTableIdList, compareTableIdInfo); taosArraySort(pTableIdList, compareTableIdInfo);
...@@ -5693,7 +5701,8 @@ static int32_t initQInfo(SQueryTableMsg *pQueryMsg, void *tsdb, int32_t vgId, SQ ...@@ -5693,7 +5701,8 @@ static int32_t initQInfo(SQueryTableMsg *pQueryMsg, void *tsdb, int32_t vgId, SQ
pTSBuf = tsBufCreateFromCompBlocks(tsBlock, pQueryMsg->tsNumOfBlocks, pQueryMsg->tsLen, pQueryMsg->tsOrder); pTSBuf = tsBufCreateFromCompBlocks(tsBlock, pQueryMsg->tsNumOfBlocks, pQueryMsg->tsLen, pQueryMsg->tsOrder);
tsBufResetPos(pTSBuf); tsBufResetPos(pTSBuf);
tsBufNextPos(pTSBuf); bool ret = tsBufNextPos(pTSBuf);
UNUSED(ret);
} }
// only the successful complete requries the sem_post/over = 1 operations. // only the successful complete requries the sem_post/over = 1 operations.
...@@ -5839,18 +5848,23 @@ static int32_t doDumpQueryResult(SQInfo *pQInfo, char *data) { ...@@ -5839,18 +5848,23 @@ static int32_t doDumpQueryResult(SQInfo *pQInfo, char *data) {
// make sure file exist // make sure file exist
if (FD_VALID(fd)) { if (FD_VALID(fd)) {
size_t s = lseek(fd, 0, SEEK_END); int32_t s = lseek(fd, 0, SEEK_END);
qTrace("QInfo:%p ts comp data return, file:%s, size:%zu", pQInfo, pQuery->sdata[0]->data, s); UNUSED(s);
qTrace("QInfo:%p ts comp data return, file:%s, size:%d", pQInfo, pQuery->sdata[0]->data, s);
lseek(fd, 0, SEEK_SET); s = lseek(fd, 0, SEEK_SET);
read(fd, data, s); if (s >= 0) {
size_t sz = read(fd, data, s);
UNUSED(sz);
}
close(fd); close(fd);
unlink(pQuery->sdata[0]->data); unlink(pQuery->sdata[0]->data);
} else { } else {
// todo return the error code to client // todo return the error code to client and handle invalid fd
qError("QInfo:%p failed to open tmp file to send ts-comp data to client, path:%s, reason:%s", pQInfo, qError("QInfo:%p failed to open tmp file to send ts-comp data to client, path:%s, reason:%s", pQInfo,
pQuery->sdata[0]->data, strerror(errno)); pQuery->sdata[0]->data, strerror(errno));
if (fd != -1) {
close(fd);
}
} }
// all data returned, set query over // all data returned, set query over
...@@ -5903,7 +5917,6 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi ...@@ -5903,7 +5917,6 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi
} }
if ((code = createQFunctionExprFromMsg(pQueryMsg, &pExprs, pExprMsg, pTagColumnInfo)) != TSDB_CODE_SUCCESS) { if ((code = createQFunctionExprFromMsg(pQueryMsg, &pExprs, pExprMsg, pTagColumnInfo)) != TSDB_CODE_SUCCESS) {
free(pExprMsg);
goto _over; goto _over;
} }
...@@ -5975,6 +5988,7 @@ _over: ...@@ -5975,6 +5988,7 @@ _over:
} }
free(pTagColumnInfo); free(pTagColumnInfo);
free(pExprs); free(pExprs);
free(pExprMsg);
taosArrayDestroy(pTableIdList); taosArrayDestroy(pTableIdList);
//pQInfo already freed in initQInfo, but *pQInfo may not pointer to null; //pQInfo already freed in initQInfo, but *pQInfo may not pointer to null;
......
...@@ -880,8 +880,11 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction) ...@@ -880,8 +880,11 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction)
for (uint32_t jx = 0; jx < pFlushInfo->numOfPages; ++jx) { for (uint32_t jx = 0; jx < pFlushInfo->numOfPages; ++jx) {
size_t sz = fread(pPage, pMemBuffer->pageSize, 1, pMemBuffer->file); size_t sz = fread(pPage, pMemBuffer->pageSize, 1, pMemBuffer->file);
UNUSED(sz); if (sz != pMemBuffer->pageSize) {
tMemBucketPut(pMemBucket, pPage->data, pPage->num); uError("MemBucket:%p, read tmp file %s failed", pMemBucket, pMemBuffer->path);
} else {
tMemBucketPut(pMemBucket, pPage->data, pPage->num);
}
} }
fclose(pMemBuffer->file); fclose(pMemBuffer->file);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册