From a05a0806a4bc2b962571535ec2e31de42bec8c4e Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 20 Jun 2020 05:09:59 +0000 Subject: [PATCH] [TD-674] defect found in coverity scan --- src/client/inc/tsclient.h | 1 + src/client/src/tscUtil.c | 5 +++++ src/mnode/src/mnodeShow.c | 12 +++++++----- src/plugins/http/src/httpSql.c | 4 ++++ src/plugins/http/src/tgHandle.c | 8 +++++++- tests/script/general/parser/limit2.sim | 2 -- tests/tsim/src/simExe.c | 1 + 7 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 90364987bb..52e2b97e1c 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -405,6 +405,7 @@ void tscKillSTableQuery(SSqlObj *pSql); void tscInitResObjForLocalQuery(SSqlObj *pObj, int32_t numOfRes, int32_t rowLen); bool tscIsUpdateQuery(SSqlObj* pSql); bool tscHasReachLimitation(SQueryInfo *pQueryInfo, SSqlRes *pRes); +bool tscResultsetFetchCompleted(TAOS_RES *result); char *tscGetErrorMsgPayload(SSqlCmd *pCmd); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 110a435e57..4bb1fb3ed5 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1942,6 +1942,11 @@ bool tscHasReachLimitation(SQueryInfo* pQueryInfo, SSqlRes* pRes) { return (pQueryInfo->clauseLimit > 0 && pRes->numOfClauseTotal >= pQueryInfo->clauseLimit); } +bool tscResultsetFetchCompleted(TAOS_RES *result) { + SSqlRes* pRes = result; + return pRes->completed; +} + char* tscGetErrorMsgPayload(SSqlCmd* pCmd) { return pCmd->payload; } /** diff --git a/src/mnode/src/mnodeShow.c b/src/mnode/src/mnodeShow.c index fb283eb61d..996e9ced0b 100644 --- a/src/mnode/src/mnodeShow.c +++ b/src/mnode/src/mnodeShow.c @@ -65,7 +65,7 @@ int32_t mnodeInitShow() { mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_CONNECT, mnodeProcessConnectMsg); mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_USE_DB, mnodeProcessUseMsg); - tsMnodeShowCache = taosCacheInitWithCb(10, mnodeFreeShowObj); + tsMnodeShowCache = taosCacheInitWithCb(5, mnodeFreeShowObj); return 0; } @@ -139,7 +139,7 @@ static int32_t mnodeProcessShowMsg(SMnodeMsg *pMsg) { pShowRsp->qhandle = htobe64((uint64_t) pShow); int32_t code = (*tsMnodeShowMetaFp[pShowMsg->type])(&pShowRsp->tableMeta, pShow, pMsg->rpcMsg.handle); - mTrace("%p, show type:%s index:%d, get meta finished, rows:%d cols:%d result:%s", pShow, + mTrace("%p, show type:%s index:%d, get meta finished, numOfRows:%d cols:%d result:%s", pShow, mnodeGetShowType(pShowMsg->type), pShow->index, pShow->numOfRows, pShow->numOfColumns, tstrerror(code)); if (code == TSDB_CODE_SUCCESS) { @@ -179,7 +179,7 @@ static int32_t mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) { mTrace("%p, show is already read finished, numOfReads:%d numOfRows:%d", pShow, pShow->numOfReads, pShow->numOfRows); pShow->numOfReads = pShow->numOfRows; } - + if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) { rowsToRead = pShow->numOfRows - pShow->numOfReads; } @@ -219,8 +219,10 @@ static int32_t mnodeProcessRetrieveMsg(SMnodeMsg *pMsg) { if (rowsToRead == 0 || (rowsRead == rowsToRead && pShow->numOfRows == pShow->numOfReads)) { pRsp->completed = 1; + mTrace("%p, retrieve completed", pShow); mnodeReleaseShowObj(pShow, true); } else { + mTrace("%p, retrieve not completed yet", pShow); mnodeReleaseShowObj(pShow, false); } @@ -379,10 +381,10 @@ static void *mnodePutShowObj(SShowObj *pShow, int32_t size) { pShow->index = atomic_add_fetch_32(&tsShowObjIndex, 1); sprintf(key, "%d", pShow->index); - SShowObj *newQhandle = taosCachePut(tsMnodeShowCache, key, pShow, size, 60); + SShowObj *newQhandle = taosCachePut(tsMnodeShowCache, key, pShow, size, 6); free(pShow); - mTrace("%p, show is put into cache", newQhandle); + mTrace("%p, show is put into cache, index:%s", newQhandle, key); return newQhandle; } diff --git a/src/plugins/http/src/httpSql.c b/src/plugins/http/src/httpSql.c index ce2f7a83bd..9d58454460 100644 --- a/src/plugins/http/src/httpSql.c +++ b/src/plugins/http/src/httpSql.c @@ -205,6 +205,10 @@ void httpProcessSingleSqlRetrieveCallBack(void *param, TAOS_RES *result, int num } } + if (tscResultsetFetchCompleted(result)) { + isContinue = false; + } + if (isContinue) { // retrieve next batch of rows httpTrace("context:%p, fd:%d, ip:%s, user:%s, continue retrieve, numOfRows:%d", pContext, pContext->fd, diff --git a/src/plugins/http/src/tgHandle.c b/src/plugins/http/src/tgHandle.c index 354fa6b07e..17192db3ca 100644 --- a/src/plugins/http/src/tgHandle.c +++ b/src/plugins/http/src/tgHandle.c @@ -269,14 +269,20 @@ int tgReadSchema(char *fileName) { httpPrint("open telegraf schema file:%s success", fileName); fseek(fp, 0, SEEK_END); int32_t contentSize = (int32_t)ftell(fp); + if (contentSize <= 0) { + fclose(fp); + return 0; + } + rewind(fp); char * content = (char *)calloc(contentSize + 1, 1); int32_t result = fread(content, 1, contentSize, fp); + if (result != contentSize) { httpError("failed to read telegraf schema file:%s", fileName); fclose(fp); free(content); - return -1; + return 0; } content[contentSize] = 0; diff --git a/tests/script/general/parser/limit2.sim b/tests/script/general/parser/limit2.sim index d16ee29cf7..d22c786aa3 100644 --- a/tests/script/general/parser/limit2.sim +++ b/tests/script/general/parser/limit2.sim @@ -69,8 +69,6 @@ print ====== tables created print ================== restart server to commit data into disk system sh/exec.sh -n dnode1 -s stop -x SIGINT - -return sleep 5000 system sh/exec.sh -n dnode1 -s start print ================== server restart completed diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index aba9714f0a..048ee04866 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -652,6 +652,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { if (line->errorJump == SQL_JUMP_TRUE) { script->linePos = line->jump; + taos_free_result(pSql); return true; } taosMsleep(1000); -- GitLab