diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 1ef70b96e5..723eb8c62c 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -307,13 +307,15 @@ int32_t stmtCleanExecInfo(STscStmt* pStmt, bool keepTable, bool deepClean) { pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter); } - if (!keepTable) { - taosHashCleanup(pStmt->exec.pBlockHash); - pStmt->exec.pBlockHash = NULL; + if (keepTable) { + return TSDB_CODE_SUCCESS; } + + taosHashCleanup(pStmt->exec.pBlockHash); + pStmt->exec.pBlockHash = NULL; - tDestroySSubmitTbData(pStmt->exec.pCurrTbData, TSDB_MSG_FLG_DECODE); - pStmt->exec.pCurrTbData = NULL; + tDestroySSubmitTbData(pStmt->exec.pCurrTbData, TSDB_MSG_FLG_ENCODE); + taosMemoryFreeClear(pStmt->exec.pCurrTbData); STMT_ERR_RET(stmtCleanBindInfo(pStmt)); @@ -875,6 +877,9 @@ int stmtExec(TAOS_STMT* stmt) { if (STMT_TYPE_QUERY == pStmt->sql.type) { launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, true, NULL); } else { + tDestroySSubmitTbData(pStmt->exec.pCurrTbData, TSDB_MSG_FLG_ENCODE); + taosMemoryFreeClear(pStmt->exec.pCurrTbData); + STMT_ERR_RET(qCloneCurrentTbData(pStmt->exec.pCurrBlock, &pStmt->exec.pCurrTbData)); STMT_ERR_RET(qBuildStmtOutput(pStmt->sql.pQuery, pStmt->sql.pVgHash, pStmt->exec.pBlockHash)); diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 24cf6fbf5a..7f457b3f9a 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -6871,11 +6871,12 @@ void tDestroySSubmitTbData(SSubmitTbData *pTbData, int32_t flag) { return; } - if (pTbData->pCreateTbReq) { - taosMemoryFree(pTbData->pCreateTbReq); - } - if (flag == TSDB_MSG_FLG_ENCODE) { + if (pTbData->pCreateTbReq) { + tdDestroySVCreateTbReq(pTbData->pCreateTbReq); + taosMemoryFree(pTbData->pCreateTbReq); + } + if (pTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) { int32_t nColData = TARRAY_SIZE(pTbData->aCol); SColData *aColData = (SColData *)TARRAY_DATA(pTbData->aCol); @@ -6894,6 +6895,10 @@ void tDestroySSubmitTbData(SSubmitTbData *pTbData, int32_t flag) { taosArrayDestroy(pTbData->aRowP); } } else if (flag == TSDB_MSG_FLG_DECODE) { + if (pTbData->pCreateTbReq) { + taosMemoryFree(pTbData->pCreateTbReq); + } + if (pTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) { taosArrayDestroy(pTbData->aCol); } else { diff --git a/source/libs/parser/src/parInsertStmt.c b/source/libs/parser/src/parInsertStmt.c index 70a8778ba0..411f40f549 100644 --- a/source/libs/parser/src/parInsertStmt.c +++ b/source/libs/parser/src/parInsertStmt.c @@ -164,6 +164,14 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const ch goto end; } + if (NULL == pDataBlock->pData->pCreateTbReq) { + pDataBlock->pData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq)); + if (NULL == pDataBlock->pData->pCreateTbReq) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto end; + } + } + insBuildCreateTbReq(pDataBlock->pData->pCreateTbReq, tName, pTag, suid, sTableName, tagName, pDataBlock->pMeta->tableInfo.numOfTags, TSDB_DEFAULT_TABLE_TTL); end: @@ -471,7 +479,7 @@ int32_t qRebuildStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_ pBlock->pMeta->vgId = vgId; } - if (rebuildCreateTb && pBlock->pData->pCreateTbReq) { + if (rebuildCreateTb && NULL == pBlock->pData->pCreateTbReq) { pBlock->pData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq)); if (NULL == pBlock->pData->pCreateTbReq) { return TSDB_CODE_OUT_OF_MEMORY; diff --git a/source/libs/parser/src/parInsertUtil.c b/source/libs/parser/src/parInsertUtil.c index c589526e0c..1f700a26e0 100644 --- a/source/libs/parser/src/parInsertUtil.c +++ b/source/libs/parser/src/parInsertUtil.c @@ -1124,6 +1124,7 @@ void insDestroyVgroupDataCxt(SVgroupDataCxt* pVgCxt) { } tDestroySSubmitReq2(pVgCxt->pData, TSDB_MSG_FLG_ENCODE); + taosMemoryFree(pVgCxt->pData); taosMemoryFree(pVgCxt); } @@ -1240,6 +1241,16 @@ int32_t insMergeTableDataCxt(SHashObj* pTableHash, SArray** pVgDataBlocks) { while (TSDB_CODE_SUCCESS == code && NULL != p) { STableDataCxt* pTableCxt = *(STableDataCxt**)p; if (colFormat) { + SColData *pCol = taosArrayGet(pTableCxt->pData->aCol, 0); + if (pCol->nVal <= 0) { + p = taosHashIterate(pTableHash, p); + continue; + } + + if (pTableCxt->pData->pCreateTbReq) { + pTableCxt->pData->flags |= SUBMIT_REQ_AUTO_CREATE_TABLE; + } + taosArraySort(pTableCxt->pData->aCol, insColDataComp); tColDataSortMerge(pTableCxt->pData->aCol); @@ -1274,7 +1285,7 @@ int32_t insMergeTableDataCxt(SHashObj* pTableHash, SArray** pVgDataBlocks) { if (TSDB_CODE_SUCCESS == code) { *pVgDataBlocks = pVgroupList; } else { - taosArrayDestroy(pVgroupList); + insDestroyVgroupDataCxtList(pVgroupList); } return code; diff --git a/source/libs/qcom/src/queryUtil.c b/source/libs/qcom/src/queryUtil.c index 190d6869dc..4680847521 100644 --- a/source/libs/qcom/src/queryUtil.c +++ b/source/libs/qcom/src/queryUtil.c @@ -244,6 +244,7 @@ void destroyQueryExecRes(SExecResult* pRes) { } case TDMT_VND_SUBMIT: { tDestroySSubmitRsp2((SSubmitRsp2*)pRes->res, TSDB_MSG_FLG_DECODE); + taosMemoryFreeClear(pRes->res); break; } case TDMT_SCH_QUERY: @@ -499,27 +500,39 @@ int32_t cloneSVreateTbReq(SVCreateTbReq* pSrc, SVCreateTbReq** pDst) { } (*pDst)->flags = pSrc->flags; - (*pDst)->name = strdup(pSrc->name); + if (pSrc->name) { + (*pDst)->name = strdup(pSrc->name); + } (*pDst)->uid = pSrc->uid; (*pDst)->ctime = pSrc->ctime; (*pDst)->ttl = pSrc->ttl; (*pDst)->commentLen = pSrc->commentLen; - (*pDst)->comment = strdup(pSrc->comment); + if (pSrc->comment) { + (*pDst)->comment = strdup(pSrc->comment); + } (*pDst)->type = pSrc->type; if (pSrc->type == TSDB_CHILD_TABLE) { - (*pDst)->ctb.stbName = strdup(pSrc->ctb.stbName); + if (pSrc->ctb.stbName) { + (*pDst)->ctb.stbName = strdup(pSrc->ctb.stbName); + } (*pDst)->ctb.tagNum = pSrc->ctb.tagNum; (*pDst)->ctb.suid = pSrc->ctb.suid; - (*pDst)->ctb.tagName = taosArrayDup(pSrc->ctb.tagName, NULL); + if (pSrc->ctb.tagName) { + (*pDst)->ctb.tagName = taosArrayDup(pSrc->ctb.tagName, NULL); + } STag* pTag = (STag *)pSrc->ctb.pTag; - (*pDst)->ctb.pTag = taosMemoryMalloc(pTag->len); - memcpy((*pDst)->ctb.pTag, pTag, pTag->len); + if (pTag) { + (*pDst)->ctb.pTag = taosMemoryMalloc(pTag->len); + memcpy((*pDst)->ctb.pTag, pTag, pTag->len); + } } else { (*pDst)->ntb.schemaRow.nCols = pSrc->ntb.schemaRow.nCols; (*pDst)->ntb.schemaRow.version = pSrc->ntb.schemaRow.nCols; - (*pDst)->ntb.schemaRow.pSchema = taosMemoryMalloc(pSrc->ntb.schemaRow.nCols * sizeof(SSchema)); - memcpy((*pDst)->ntb.schemaRow.pSchema, pSrc->ntb.schemaRow.pSchema, pSrc->ntb.schemaRow.nCols * sizeof(SSchema)); + if (pSrc->ntb.schemaRow.nCols > 0 && pSrc->ntb.schemaRow.pSchema) { + (*pDst)->ntb.schemaRow.pSchema = taosMemoryMalloc(pSrc->ntb.schemaRow.nCols * sizeof(SSchema)); + memcpy((*pDst)->ntb.schemaRow.pSchema, pSrc->ntb.schemaRow.pSchema, pSrc->ntb.schemaRow.nCols * sizeof(SSchema)); + } } return TSDB_CODE_SUCCESS; diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index 4915bba085..9a61a9b710 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -262,9 +262,11 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa SSubmitRsp2 *rsp = taosMemoryMalloc(sizeof(*rsp)); tDecoderInit(&coder, msg, msgSize); code = tDecodeSSubmitRsp2(&coder, rsp); + tDecoderClear(&coder); if (code) { SCH_TASK_ELOG("tDecodeSSubmitRsp2 failed, code:%d", code); tDestroySSubmitRsp2(rsp, TSDB_MSG_FLG_DECODE); + taosMemoryFree(rsp); SCH_ERR_JRET(code); } @@ -281,11 +283,10 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa if (sum->aCreateTbRsp) { taosArrayAddAll(sum->aCreateTbRsp, rsp->aCreateTbRsp); taosArrayDestroy(rsp->aCreateTbRsp); - taosMemoryFree(rsp); } else { TSWAP(sum->aCreateTbRsp, rsp->aCreateTbRsp); - taosMemoryFree(rsp); } + taosMemoryFree(rsp); } else { pJob->execRes.res = rsp; pJob->execRes.msgType = TDMT_VND_SUBMIT; @@ -301,6 +302,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa } SCH_UNLOCK(SCH_WRITE, &pJob->resLock); tDestroySSubmitRsp2(rsp, TSDB_MSG_FLG_DECODE); + taosMemoryFree(rsp); } } diff --git a/source/util/src/tcompare.c b/source/util/src/tcompare.c index d84a3d25c6..3edd067ce2 100644 --- a/source/util/src/tcompare.c +++ b/source/util/src/tcompare.c @@ -1120,7 +1120,7 @@ int32_t WCSPatternMatch(const TdUcs4 *patterStr, const TdUcs4 *str, size_t size, return TSDB_PATTERN_NOMATCH; } - return (str[j] == 0 || j >= size) ? TSDB_PATTERN_MATCH : TSDB_PATTERN_NOMATCH; + return (j >= size || str[j] == 0) ? TSDB_PATTERN_MATCH : TSDB_PATTERN_NOMATCH; } int32_t compareStrRegexCompMatch(const void *pLeft, const void *pRight) { return compareStrRegexComp(pLeft, pRight); }