diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 50ab515e2b..4d04d4184f 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -1197,16 +1197,17 @@ int32_t tscSetTableFullName(SName* pName, SStrToken* pTableName, SSqlObj* pSql) } else { // get current DB name first, and then set it into path char* t = cloneCurrentDBName(pSql); if (strlen(t) == 0) { + tfree(t); return TSDB_CODE_TSC_DB_NOT_SELECTED; } code = tNameFromString(pName, t, T_NAME_ACCT | T_NAME_DB); if (code != 0) { - free(t); + tfree(t); return TSDB_CODE_TSC_DB_NOT_SELECTED; } - free(t); + tfree(t); if (pTableName->n >= TSDB_TABLE_NAME_LEN) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); @@ -6943,7 +6944,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { if (strncmp(sToken->z, pTagSchema[t].name, sToken->n) == 0 && strlen(pTagSchema[t].name) == sToken->n) { SSchema* pSchema = &pTagSchema[t]; - char tagVal[TSDB_MAX_TAGS_LEN]; + char tagVal[TSDB_MAX_TAGS_LEN] = {0}; if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) { if (pItem->pVar.nLen > pSchema->bytes) { tdDestroyKVRowBuilder(&kvRowBuilder); diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 4d97fef52f..8ab3512cba 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -2450,6 +2450,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { if (ret != 0) { pRes->code = ret; tscAsyncResultOnError(pSql); + tfree(pDesc); tfree(pMemoryBuf); return ret; } diff --git a/src/common/src/tname.c b/src/common/src/tname.c index c1c6ffa4b3..72e2d42ff9 100644 --- a/src/common/src/tname.c +++ b/src/common/src/tname.c @@ -256,7 +256,7 @@ int32_t tNameExtractFullName(const SName* name, char* dst) { return -1; } - int32_t len = snprintf(dst, TSDB_ACCT_ID_LEN + 1 + TSDB_DB_NAME_LEN, "%s.%s", name->acctId, name->dbname); + int32_t len = snprintf(dst, TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN, "%s.%s", name->acctId, name->dbname); size_t tnameLen = strlen(name->tname); if (tnameLen > 0) { diff --git a/src/common/src/tvariant.c b/src/common/src/tvariant.c index 1168eeb231..9e0f7ffc74 100644 --- a/src/common/src/tvariant.c +++ b/src/common/src/tvariant.c @@ -407,6 +407,7 @@ static int32_t toNchar(tVariant *pVariant, char **pDest, int32_t *pDestSize) { wchar_t *pWStr = calloc(1, (nLen + 1) * TSDB_NCHAR_SIZE); bool ret = taosMbsToUcs4(pDst, nLen, (char *)pWStr, (nLen + 1) * TSDB_NCHAR_SIZE, NULL); if (!ret) { + tfree(pWStr); return -1; } @@ -606,7 +607,7 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu } errno = 0; // reset global error code - int64_t result; + int64_t result = 0; switch (type) { case TSDB_DATA_TYPE_BOOL: { @@ -874,7 +875,8 @@ int32_t tVariantTypeSetType(tVariant *pVariant, char type) { free(pVariant->pz); pVariant->dKey = v; } else if (pVariant->nType >= TSDB_DATA_TYPE_BOOL && pVariant->nType <= TSDB_DATA_TYPE_BIGINT) { - pVariant->dKey = (double)(pVariant->i64); + double tmp = (double) pVariant->i64; + pVariant->dKey = tmp; } pVariant->nType = TSDB_DATA_TYPE_DOUBLE; diff --git a/src/inc/ttype.h b/src/inc/ttype.h index 9949f31c59..61c90c92a6 100644 --- a/src/inc/ttype.h +++ b/src/inc/ttype.h @@ -119,7 +119,7 @@ typedef struct tstr { #define IS_VALID_UTINYINT(_t) ((_t) >= 0 && (_t) < UINT8_MAX) #define IS_VALID_USMALLINT(_t) ((_t) >= 0 && (_t) < UINT16_MAX) #define IS_VALID_UINT(_t) ((_t) >= 0 && (_t) < UINT32_MAX) -#define IS_VALID_UBIGINT(_t) ((_t) >= 0 && (_t) < UINT64_MAX) +#define IS_VALID_UBIGINT(_t) ((_t) >= 0 /*&& (_t) < UINT64_MAX*/) static FORCE_INLINE bool isNull(const char *val, int32_t type) { switch (type) { diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 189c4b6005..4c5ee032b7 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -1058,7 +1058,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { return TSDB_CODE_MND_TOO_MANY_COLUMNS; } - SSTableObj * pStable = calloc(1, sizeof(SSTableObj)); + SSTableObj *pStable = calloc(1, sizeof(SSTableObj)); if (pStable == NULL) { mError("msg:%p, app:%p table:%s, failed to create, no enough memory", pMsg, pMsg->rpcMsg.ahandle, pCreate->tableName); return TSDB_CODE_MND_OUT_OF_MEMORY; @@ -1068,8 +1068,10 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { pStable->info.tableId = strdup(pCreate->tableName); pStable->info.type = TSDB_SUPER_TABLE; pStable->createdTime = taosGetTimestampMs(); - uint64_t x = (us&0x000000FFFFFFFFFF); - x = x<<24; + + uint64_t x = (us & ((1ul<<40) - 1)); // todo refactor + x = x << 24; + pStable->uid = x + ((sdbGetVersion() & ((1ul << 16) - 1ul)) << 8) + (taosRand() & ((1ul << 8) - 1ul)); pStable->sversion = 0; pStable->tversion = 0; @@ -1079,7 +1081,8 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { int32_t schemaSize = numOfCols * sizeof(SSchema); pStable->schema = (SSchema *)calloc(1, schemaSize); if (pStable->schema == NULL) { - free(pStable); + tfree(pStable->info.tableId); + tfree(pStable); mError("msg:%p, app:%p table:%s, failed to create, no schema input", pMsg, pMsg->rpcMsg.ahandle, pCreate->tableName); return TSDB_CODE_MND_INVALID_TABLE_NAME; } @@ -1096,6 +1099,9 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { if (!tIsValidSchema(pStable->schema, pStable->numOfColumns, pStable->numOfTags)) { mError("msg:%p, app:%p table:%s, failed to create table, invalid schema", pMsg, pMsg->rpcMsg.ahandle, pCreate->tableName); + tfree(pStable->info.tableId); + tfree(pStable->schema); + tfree(pStable); return TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG; } diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index a7e36f7032..b17aa755a5 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -488,6 +488,7 @@ TsdbQueryHandleT* tsdbQueryTables(STsdbRepo* tsdb, STsdbQueryCond* pCond, STable pQueryHandle->pTableCheckInfo = createCheckInfoFromTableGroup(pQueryHandle, groupList, pMeta, &psTable); if (pQueryHandle->pTableCheckInfo == NULL) { tsdbCleanupQueryHandle(pQueryHandle); + taosArrayDestroy(psTable); terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return NULL; } @@ -575,8 +576,6 @@ void tsdbResetQueryHandleForNewTable(TsdbQueryHandleT queryHandle, STsdbQueryCon pQueryHandle->next = doFreeColumnInfoData(pQueryHandle->next); } - - TsdbQueryHandleT tsdbQueryLastRow(STsdbRepo *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, uint64_t qId, SMemRef* pMemRef) { pCond->twindow = updateLastrowForEachGroup(groupList); @@ -2874,6 +2873,7 @@ static int32_t doGetExternalRow(STsdbQueryHandle* pQueryHandle, int16_t type, SM SArray* psTable = NULL; pSecQueryHandle->pTableCheckInfo = createCheckInfoFromCheckInfo(pCurrent, pSecQueryHandle->window.skey, &psTable); if (pSecQueryHandle->pTableCheckInfo == NULL) { + taosArrayDestroy(psTable); terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; goto out_of_memory; }