From 02d509e6a7c70469b39389006ecb150ec8485fee Mon Sep 17 00:00:00 2001 From: fang Date: Mon, 9 Dec 2019 09:40:23 +0800 Subject: [PATCH 1/8] solve static check questions --- src/client/src/tscPrepare.c | 2 +- src/client/src/tscProfile.c | 2 +- src/client/src/tscSQLParser.c | 42 +++++++++++++++++------------------ 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 7e62afefe6..8b8361fc8d 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -65,6 +65,7 @@ static int normalStmtAddPart(SNormalStmt* stmt, bool isParam, char* str, uint32_ } stmt->sizeParts = size; stmt->parts = (SNormalStmtPart*)tmp; + free(tmp); //fang memory leak } stmt->parts[stmt->numParts].isParam = isParam; @@ -75,7 +76,6 @@ static int normalStmtAddPart(SNormalStmt* stmt, bool isParam, char* str, uint32_ if (isParam) { ++stmt->numParams; } - return TSDB_CODE_SUCCESS; } diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c index 61bc9dd99e..930198cbc3 100644 --- a/src/client/src/tscProfile.c +++ b/src/client/src/tscProfile.c @@ -198,7 +198,7 @@ void tscKillStream(STscObj *pObj, uint32_t killId) { pthread_mutex_unlock(&pObj->mutex); - tscTrace("%p stream:%p is killed, streamId:%d", pStream->pSql, pStream, killId); + tscTrace("%p stream:%p is killed, streamId:%d", pStream->pSql, pStream, killId); //fang, pStream could be null taos_close_stream(pStream); if (pStream->callback) { diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 752c5d123f..20e4c3e518 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -248,7 +248,6 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { } case USE_DATABASE: { - const char* msg = "db name too long"; pCmd->command = TSDB_SQL_USE_DB; SSQLToken* pToken = &pInfo->pDCLInfo->a[0]; @@ -258,6 +257,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { } if (pToken->n > TSDB_DB_NAME_LEN) { + const char* msg = "db name too long"; //fang, reduce scope return invalidSqlErrMsg(pCmd, msg); } @@ -295,8 +295,6 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { case ALTER_DATABASE: case CREATE_DATABASE: { - const char* msg2 = "name too long"; - const char* msg3 = "invalid db name"; if (pInfo->sqlType == ALTER_DATABASE) { pCmd->command = TSDB_SQL_ALTER_DB; @@ -307,11 +305,13 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { SCreateDBInfo* pCreateDB = &(pInfo->pDCLInfo->dbOpt); if (tscValidateName(&pCreateDB->dbname) != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(pCmd, msg3); + const char* msg3 = "invalid db name"; + return invalidSqlErrMsg(pCmd, msg3);//fang reduce scope } int32_t ret = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), &(pCreateDB->dbname), NULL, NULL); if (ret != TSDB_CODE_SUCCESS) { + const char* msg2 = "name too long"; //fang reduce scope return invalidSqlErrMsg(pCmd, msg2); } @@ -347,14 +347,9 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { pCmd->command = (pInfo->sqlType == CREATE_USER) ? TSDB_SQL_CREATE_USER : TSDB_SQL_CREATE_ACCT; assert(pInfo->pDCLInfo->nTokens >= 2); - const char* msg = "name or password too long"; - const char* msg1 = "password can not be empty"; - const char* msg2 = "invalid user/account name"; - const char* msg3 = "password needs single quote marks enclosed"; - const char* msg4 = "invalid state option, available options[no, r, w, all]"; - if (pInfo->pDCLInfo->a[1].type != TK_STRING) { - return invalidSqlErrMsg(pCmd, msg3); + const char* msg3 = "password needs single quote marks enclosed"; + return invalidSqlErrMsg(pCmd, msg3);//fang reduce scope } strdequote(pInfo->pDCLInfo->a[1].z); @@ -362,15 +357,18 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { pInfo->pDCLInfo->a[1].n = strlen(pInfo->pDCLInfo->a[1].z); if (pInfo->pDCLInfo->a[1].n <= 0) { - return invalidSqlErrMsg(pCmd, msg1); + const char* msg1 = "password can not be empty"; + return invalidSqlErrMsg(pCmd, msg1);//fang reduce scope } if (pInfo->pDCLInfo->a[0].n > TSDB_USER_LEN || pInfo->pDCLInfo->a[1].n > TSDB_PASSWORD_LEN) { - return invalidSqlErrMsg(pCmd, msg); + const char* msg = "name or password too long"; + return invalidSqlErrMsg(pCmd, msg); //fang reduce scope } if (tscValidateName(&pInfo->pDCLInfo->a[0]) != TSDB_CODE_SUCCESS) { - return invalidSqlErrMsg(pCmd, msg2); + const char* msg2 = "invalid user/account name"; + return invalidSqlErrMsg(pCmd, msg2); //fang reduce scope } strncpy(pMeterMetaInfo->name, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n); // name @@ -403,7 +401,8 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { } else if (strncmp(pAcctOpt->stat.z, "no", 2) == 0 && pAcctOpt->stat.n == 2) { pCmd->defaultVal[8] = 0; } else { - return invalidSqlErrMsg(pCmd, msg4); + const char* msg4 = "invalid state option, available options[no, r, w, all]"; + return invalidSqlErrMsg(pCmd, msg4); //fang reduce scope } } } @@ -415,13 +414,10 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { assert(num >= 1 && num <= 2); const char* msg = "password too long"; - const char* msg1 = "password can not be empty"; - const char* msg2 = "invalid user/account name"; - const char* msg3 = "password needs single quote marks enclosed"; - const char* msg4 = "invalid state option, available options[no, r, w, all]"; if (num == 2) { if (pInfo->pDCLInfo->a[1].type != TK_STRING) { + const char* msg3 = "password needs single quote marks enclosed"; return invalidSqlErrMsg(pCmd, msg3); } @@ -430,6 +426,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { pInfo->pDCLInfo->a[1].n = strlen(pInfo->pDCLInfo->a[1].z); if (pInfo->pDCLInfo->a[1].n <= 0) { + const char* msg1 = "password can not be empty"; return invalidSqlErrMsg(pCmd, msg1); } @@ -445,6 +442,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { } if (tscValidateName(&pInfo->pDCLInfo->a[0]) != TSDB_CODE_SUCCESS) { + const char* msg2 = "invalid user/account name"; return invalidSqlErrMsg(pCmd, msg2); } @@ -475,6 +473,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { } else if (strncmp(pAcctOpt->stat.z, "no", 2) == 0 && pAcctOpt->stat.n == 2) { pCmd->defaultVal[8] = 0; } else { + const char* msg4 = "invalid state option, available options[no, r, w, all]"; return invalidSqlErrMsg(pCmd, msg4); } } @@ -1868,8 +1867,6 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem SMeterMetaInfo* pMeterMetaInfo = NULL; int32_t optr = pItem->pNode->nSQLOptr; - int32_t numOfAddedColumn = 1; - const char* msg1 = "not support column types"; const char* msg2 = "invalid parameters"; const char* msg3 = "illegal column name"; @@ -2166,6 +2163,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem int16_t resultSize = pSchema[index.columnIndex].bytes; char val[8] = {0}; + int32_t numOfAddedColumn = 1; //fang reduce scope if (optr == TK_PERCENTILE || optr == TK_APERCENTILE) { tVariantDump(pVariant, val, TSDB_DATA_TYPE_DOUBLE); @@ -2190,6 +2188,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem SSqlExpr* pExpr = tscSqlExprInsert(pCmd, colIdx, functionId, &index, resultType, resultSize, resultSize); addExprParams(pExpr, val, TSDB_DATA_TYPE_DOUBLE, sizeof(double), 0); } else { + tVariantDump(pVariant, val, TSDB_DATA_TYPE_BIGINT); int64_t nTop = *((int32_t*)val); @@ -2928,6 +2927,7 @@ static SColumnFilterInfo* addColumnFilterInfo(SColumnBase* pColumn) { char* tmp = realloc(pColumn->filterInfo, sizeof(SColumnFilterInfo) * (size)); if (tmp != NULL) { pColumn->filterInfo = (SColumnFilterInfo*)tmp; + free(tmp); //fang, memory leak } pColumn->numOfFilters++; From b93b86862a7b5b9760a602562a20d7451b324b29 Mon Sep 17 00:00:00 2001 From: fang Date: Mon, 9 Dec 2019 10:00:02 +0800 Subject: [PATCH 2/8] solve static check --- src/client/src/tscPrepare.c | 2 +- src/client/src/tscProfile.c | 6 ++++-- src/client/src/tscSQLParser.c | 20 ++++++++++---------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 8b8361fc8d..2f1db58117 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -65,7 +65,7 @@ static int normalStmtAddPart(SNormalStmt* stmt, bool isParam, char* str, uint32_ } stmt->sizeParts = size; stmt->parts = (SNormalStmtPart*)tmp; - free(tmp); //fang memory leak + free(tmp); } stmt->parts[stmt->numParts].isParam = isParam; diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c index 930198cbc3..15390ef201 100644 --- a/src/client/src/tscProfile.c +++ b/src/client/src/tscProfile.c @@ -197,8 +197,10 @@ void tscKillStream(STscObj *pObj, uint32_t killId) { } pthread_mutex_unlock(&pObj->mutex); - - tscTrace("%p stream:%p is killed, streamId:%d", pStream->pSql, pStream, killId); //fang, pStream could be null + + if (pStream) { + tscTrace("%p stream:%p is killed, streamId:%d", pStream->pSql, pStream, killId); + } taos_close_stream(pStream); if (pStream->callback) { diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 20e4c3e518..cb73a6e9bd 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -257,7 +257,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { } if (pToken->n > TSDB_DB_NAME_LEN) { - const char* msg = "db name too long"; //fang, reduce scope + const char* msg = "db name too long"; return invalidSqlErrMsg(pCmd, msg); } @@ -306,12 +306,12 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { SCreateDBInfo* pCreateDB = &(pInfo->pDCLInfo->dbOpt); if (tscValidateName(&pCreateDB->dbname) != TSDB_CODE_SUCCESS) { const char* msg3 = "invalid db name"; - return invalidSqlErrMsg(pCmd, msg3);//fang reduce scope + return invalidSqlErrMsg(pCmd, msg3); } int32_t ret = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), &(pCreateDB->dbname), NULL, NULL); if (ret != TSDB_CODE_SUCCESS) { - const char* msg2 = "name too long"; //fang reduce scope + const char* msg2 = "name too long"; return invalidSqlErrMsg(pCmd, msg2); } @@ -349,7 +349,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { if (pInfo->pDCLInfo->a[1].type != TK_STRING) { const char* msg3 = "password needs single quote marks enclosed"; - return invalidSqlErrMsg(pCmd, msg3);//fang reduce scope + return invalidSqlErrMsg(pCmd, msg3); } strdequote(pInfo->pDCLInfo->a[1].z); @@ -358,17 +358,17 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { if (pInfo->pDCLInfo->a[1].n <= 0) { const char* msg1 = "password can not be empty"; - return invalidSqlErrMsg(pCmd, msg1);//fang reduce scope + return invalidSqlErrMsg(pCmd, msg1); } if (pInfo->pDCLInfo->a[0].n > TSDB_USER_LEN || pInfo->pDCLInfo->a[1].n > TSDB_PASSWORD_LEN) { const char* msg = "name or password too long"; - return invalidSqlErrMsg(pCmd, msg); //fang reduce scope + return invalidSqlErrMsg(pCmd, msg); } if (tscValidateName(&pInfo->pDCLInfo->a[0]) != TSDB_CODE_SUCCESS) { const char* msg2 = "invalid user/account name"; - return invalidSqlErrMsg(pCmd, msg2); //fang reduce scope + return invalidSqlErrMsg(pCmd, msg2); } strncpy(pMeterMetaInfo->name, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n); // name @@ -402,7 +402,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { pCmd->defaultVal[8] = 0; } else { const char* msg4 = "invalid state option, available options[no, r, w, all]"; - return invalidSqlErrMsg(pCmd, msg4); //fang reduce scope + return invalidSqlErrMsg(pCmd, msg4); } } } @@ -2163,7 +2163,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem int16_t resultSize = pSchema[index.columnIndex].bytes; char val[8] = {0}; - int32_t numOfAddedColumn = 1; //fang reduce scope + int32_t numOfAddedColumn = 1; if (optr == TK_PERCENTILE || optr == TK_APERCENTILE) { tVariantDump(pVariant, val, TSDB_DATA_TYPE_DOUBLE); @@ -2927,7 +2927,7 @@ static SColumnFilterInfo* addColumnFilterInfo(SColumnBase* pColumn) { char* tmp = realloc(pColumn->filterInfo, sizeof(SColumnFilterInfo) * (size)); if (tmp != NULL) { pColumn->filterInfo = (SColumnFilterInfo*)tmp; - free(tmp); //fang, memory leak + free(tmp); } pColumn->numOfFilters++; From 2e2e8beacb0c66c7f9f11af00e4df1c936f1ca75 Mon Sep 17 00:00:00 2001 From: fang Date: Mon, 9 Dec 2019 11:49:03 +0800 Subject: [PATCH 3/8] solve static check questions --- src/client/src/tscSecondaryMerge.c | 6 ++++-- src/client/src/tscServer.c | 1 + src/client/src/tscSystem.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/client/src/tscSecondaryMerge.c b/src/client/src/tscSecondaryMerge.c index 5eebddca73..737c1342d8 100644 --- a/src/client/src/tscSecondaryMerge.c +++ b/src/client/src/tscSecondaryMerge.c @@ -1314,8 +1314,10 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) { tscTrace("%s call the drop local reducer", __FUNCTION__); tscDestroyLocalReducer(pSql); - pRes->numOfRows = 0; - pRes->row = 0; + if (pRes) { + pRes->numOfRows = 0; + pRes->row = 0; + } return 0; } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 1805eac38d..ed21a82be1 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2312,6 +2312,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql) { size = tscEstimateCreateTableMsgLength(pSql); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { tscError("%p failed to malloc for create table msg", pSql); + free(tmpData); return -1; } diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 60b90ac328..2ebd1cfc51 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -230,7 +230,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { return -1; } - if (cfg && cfg && cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { + if (cfg && cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { char sep = '.'; if (strlen(tsLocale) == 0) { // locale does not set yet From cf014abd96d123a2ce243b9663ab22c1b22c330e Mon Sep 17 00:00:00 2001 From: fang Date: Mon, 9 Dec 2019 13:09:32 +0800 Subject: [PATCH 4/8] solve some static check questions for shell/src/ --- src/kit/shell/src/shellEngine.c | 3 +++ src/kit/shell/src/shellLinux.c | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index c66f6f4be7..ed3b71bfcd 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -780,6 +780,7 @@ void source_file(TAOS *con, char *fptr) { if (wordexp(fptr, &full_path, 0) != 0) { fprintf(stderr, "ERROR: illegal file name\n"); + free(cmd); return; } @@ -788,6 +789,7 @@ void source_file(TAOS *con, char *fptr) { if (access(fname, R_OK) == -1) { fprintf(stderr, "ERROR: file %s is not readable\n", fptr); wordfree(&full_path); + free(cmd); return; } @@ -795,6 +797,7 @@ void source_file(TAOS *con, char *fptr) { if (f == NULL) { fprintf(stderr, "ERROR: failed to open file %s\n", fname); wordfree(&full_path); + free(cmd); return; } diff --git a/src/kit/shell/src/shellLinux.c b/src/kit/shell/src/shellLinux.c index ad8bf6c5c3..2e2c44af1a 100644 --- a/src/kit/shell/src/shellLinux.c +++ b/src/kit/shell/src/shellLinux.c @@ -277,7 +277,10 @@ void *shellLoopQuery(void *arg) { pthread_cleanup_push(cleanup_handler, NULL); char *command = malloc(MAX_COMMAND_SIZE); - + if (command == NULL){ + tscError("failed to malloc command"); + return NULL; + } while (1) { // Read command from shell. @@ -286,10 +289,8 @@ void *shellLoopQuery(void *arg) { shellReadCommand(con, command); reset_terminal_mode(); - if (command != NULL) { - // Run the command - shellRunCommand(con, command); - } + // Run the command + shellRunCommand(con, command); } pthread_cleanup_pop(1); From 966623a69275fac4524edb379752b8032379300f Mon Sep 17 00:00:00 2001 From: fang Date: Mon, 9 Dec 2019 13:29:34 +0800 Subject: [PATCH 5/8] slove some static check questions for http modules --- src/modules/http/src/gcJson.c | 2 +- src/modules/http/src/restJson.c | 2 +- src/modules/http/src/tgHandle.c | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/modules/http/src/gcJson.c b/src/modules/http/src/gcJson.c index 0cb20ec7e1..ecd9235644 100644 --- a/src/modules/http/src/gcJson.c +++ b/src/modules/http/src/gcJson.c @@ -119,7 +119,7 @@ bool gcBuildQueryJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, cmd->numOfRows += numOfRows; } - for (int i = 0; i < numOfRows; ++i) { + for (int k = 0; k < numOfRows; ++k) { TAOS_ROW row = taos_fetch_row(result); // for group by diff --git a/src/modules/http/src/restJson.c b/src/modules/http/src/restJson.c index 8aa0ac5069..6c04d39f45 100644 --- a/src/modules/http/src/restJson.c +++ b/src/modules/http/src/restJson.c @@ -94,7 +94,7 @@ bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, int num_fields = taos_num_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result); - for (int i = 0; i < numOfRows; ++i) { + for (int k = 0; k < numOfRows; ++k) { TAOS_ROW row = taos_fetch_row(result); // data row array begin diff --git a/src/modules/http/src/tgHandle.c b/src/modules/http/src/tgHandle.c index ac17d6da09..80a178c776 100644 --- a/src/modules/http/src/tgHandle.c +++ b/src/modules/http/src/tgHandle.c @@ -262,6 +262,8 @@ int tgReadSchema(const char *fileName) { size_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; } From 2e0929f163655c2aa3071a0ed5b885cde55e9972 Mon Sep 17 00:00:00 2001 From: fang Date: Mon, 9 Dec 2019 13:57:25 +0800 Subject: [PATCH 6/8] solve some static check questions for os/linux/src --- src/os/linux/src/tsystem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/os/linux/src/tsystem.c b/src/os/linux/src/tsystem.c index 03192bb9cc..0a9d97b3cf 100644 --- a/src/os/linux/src/tsystem.c +++ b/src/os/linux/src/tsystem.c @@ -124,7 +124,7 @@ bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { } char cpu[10] = {0}; - sscanf(line, "%s %ld %ld %ld %ld", cpu, &cpuInfo->user, &cpuInfo->nice, &cpuInfo->system, &cpuInfo->idle); + sscanf(line, "%s %lu %lu %lu %lu", cpu, &cpuInfo->user, &cpuInfo->nice, &cpuInfo->system, &cpuInfo->idle); tfree(line); fclose(fp); @@ -150,7 +150,7 @@ bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { for (int i = 0, blank = 0; line[i] != 0; ++i) { if (line[i] == ' ') blank++; if (blank == PROCESS_ITEM) { - sscanf(line + i + 1, "%ld %ld %ld %ld", &cpuInfo->utime, &cpuInfo->stime, &cpuInfo->cutime, &cpuInfo->cstime); + sscanf(line + i + 1, "%lu %lu %lu %lu", &cpuInfo->utime, &cpuInfo->stime, &cpuInfo->cutime, &cpuInfo->cstime); break; } } From 6e473f1ef1da25b61439a6397dcccc30df0295ee Mon Sep 17 00:00:00 2001 From: fang Date: Mon, 9 Dec 2019 15:12:48 +0800 Subject: [PATCH 7/8] solve some static check questions --- src/system/detail/src/mgmtVgroup.c | 1 + src/system/detail/src/vnodeQueryImpl.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/system/detail/src/mgmtVgroup.c b/src/system/detail/src/mgmtVgroup.c index e3bed57b33..2bc1801a68 100644 --- a/src/system/detail/src/mgmtVgroup.c +++ b/src/system/detail/src/mgmtVgroup.c @@ -289,6 +289,7 @@ int mgmtRetrieveVgroups(SShowObj *pShow, char *data, int rows, SConnObj *pConn) SDbObj *pDb = NULL; if (pConn->pDb != NULL) pDb = mgmtGetDb(pConn->pDb->name); + assert(pDb != NULL); pVgroup = pDb->pHead; while (pVgroup != NULL) { diff --git a/src/system/detail/src/vnodeQueryImpl.c b/src/system/detail/src/vnodeQueryImpl.c index 5174753d82..d5809d1b72 100644 --- a/src/system/detail/src/vnodeQueryImpl.c +++ b/src/system/detail/src/vnodeQueryImpl.c @@ -4555,8 +4555,7 @@ static void doMerge(SQueryRuntimeEnv *pRuntimeEnv, int64_t timestamp, tFilePage } static void printBinaryData(int32_t functionId, char *data, int32_t srcDataType) { - if (functionId == TSDB_FUNC_FIRST_DST || functionId == TSDB_FUNC_LAST_DST || functionId == TSDB_FUNC_FIRST_DST || - functionId == TSDB_FUNC_LAST_DST) { + if (functionId == TSDB_FUNC_FIRST_DST || functionId == TSDB_FUNC_LAST_DST) { switch (srcDataType) { case TSDB_DATA_TYPE_BINARY: printf("%ld,%s\t", *(TSKEY *)data, (data + TSDB_KEYSIZE + 1)); From c2a2c575a114378a2cc8f6f992b778dbef1215ef Mon Sep 17 00:00:00 2001 From: fang Date: Tue, 10 Dec 2019 08:46:01 +0800 Subject: [PATCH 8/8] solve some statich check questions --- src/client/src/tscPrepare.c | 1 - src/client/src/tscSQLParser.c | 1 - 2 files changed, 2 deletions(-) diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 2f1db58117..ef8ddfd211 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -65,7 +65,6 @@ static int normalStmtAddPart(SNormalStmt* stmt, bool isParam, char* str, uint32_ } stmt->sizeParts = size; stmt->parts = (SNormalStmtPart*)tmp; - free(tmp); } stmt->parts[stmt->numParts].isParam = isParam; diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index cb73a6e9bd..ac2b958be7 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -2927,7 +2927,6 @@ static SColumnFilterInfo* addColumnFilterInfo(SColumnBase* pColumn) { char* tmp = realloc(pColumn->filterInfo, sizeof(SColumnFilterInfo) * (size)); if (tmp != NULL) { pColumn->filterInfo = (SColumnFilterInfo*)tmp; - free(tmp); } pColumn->numOfFilters++;