fix mem leak

This commit is contained in:
yihaoDeng 2024-11-25 15:22:53 +08:00
parent 97e08abe8c
commit 4d857b0149
10 changed files with 49 additions and 46 deletions

View File

@ -352,7 +352,6 @@ typedef enum ENodeType {
QUERY_NODE_CREATE_ANODE_STMT,
QUERY_NODE_DROP_ANODE_STMT,
QUERY_NODE_UPDATE_ANODE_STMT,
QUERY_NODE_ALTER_TABLE_MULTI_STMT,
// show statement nodes
// see 'sysTableShowAdapter', 'SYSTABLE_SHOW_TYPE_OFFSET'

View File

@ -267,18 +267,6 @@ typedef struct SAlterTableStmt {
SNodeList* pNodeListTagValue;
} SAlterTableStmt;
typedef struct SAlterTableStmt2 {
ENodeType type;
int8_t alterType;
char colName[TSDB_COL_NAME_LEN];
STableOptions* pOptions;
SDataType dataType;
SValueNode* pVal;
SColumnOptions* pColOptions;
} SAlterTableStmt2;
typedef struct SAlterTableMultiStmt {
ENodeType type;
char dbName[TSDB_DB_NAME_LEN];

View File

@ -10521,7 +10521,7 @@ int32_t tEncodeSVAlterTbReq(SEncoder *pEncoder, const SVAlterTbReq *pReq) {
TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTag->isNull));
TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTag->tagType));
if (!pTag->isNull) {
TAOS_CHECK_EXIT(tEncodeBinary(pEncoder, pTag->pTagVal, pReq->nTagVal));
TAOS_CHECK_EXIT(tEncodeBinary(pEncoder, pTag->pTagVal, pTag->nTagVal));
}
}
break;

View File

@ -2109,7 +2109,7 @@ static int metaUpdateTableMultiTagVal(SMeta *pMeta, int64_t version, SVAlterTbRe
}
int32_t nTagVals = taosArrayGetSize(pAlterTbReq->pMultiTag);
pTagTable = taosHashInit(nTagVals, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
pTagTable = taosHashInit(nTagVals, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
if (pTagTable == NULL) {
ret = terrno;
goto _err;
@ -2143,7 +2143,7 @@ static int metaUpdateTableMultiTagVal(SMeta *pMeta, int64_t version, SVAlterTbRe
}
iCol++;
}
if (taosArrayGetSize(updateTagColumnIds) == nUpdateTagVal) {
if (taosArrayGetSize(updateTagColumnIds) != nUpdateTagVal) {
terrno = TSDB_CODE_VND_COL_NOT_EXISTS;
goto _err;
}

View File

@ -145,8 +145,12 @@ static int32_t vnodePreProcessAlterTableMsg(SVnode *pVnode, SRpcMsg *pMsg) {
SVAlterTbReq vAlterTbReq = {0};
int64_t ctimeMs = taosGetTimestampMs();
if (tDecodeSVAlterTbReqSetCtime(&dc, &vAlterTbReq, ctimeMs) < 0) {
taosArrayDestroy(vAlterTbReq.pMultiTag);
vAlterTbReq.pMultiTag = NULL;
goto _exit;
}
taosArrayDestroy(vAlterTbReq.pMultiTag);
vAlterTbReq.pMultiTag = NULL;
code = 0;
@ -666,10 +670,9 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg
}
} break;
case TDMT_VND_STREAM_TASK_RESET: {
if (pVnode->restored && vnodeIsLeader(pVnode) &&
(code = tqProcessTaskResetReq(pVnode->pTq, pMsg)) < 0) {
goto _err;
}
if (pVnode->restored && vnodeIsLeader(pVnode) && (code = tqProcessTaskResetReq(pVnode->pTq, pMsg)) < 0) {
goto _err;
}
} break;
case TDMT_VND_ALTER_CONFIRM:
@ -690,7 +693,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg
case TDMT_VND_DROP_INDEX:
vnodeProcessDropIndexReq(pVnode, ver, pReq, len, pRsp);
break;
case TDMT_VND_STREAM_CHECK_POINT_SOURCE: // always return true
case TDMT_VND_STREAM_CHECK_POINT_SOURCE: // always return true
tqProcessTaskCheckPointSourceReq(pVnode->pTq, pMsg, pRsp);
break;
case TDMT_VND_STREAM_TASK_UPDATE: // always return true
@ -1367,6 +1370,7 @@ static int32_t vnodeProcessAlterTbReq(SVnode *pVnode, int64_t ver, void *pReq, i
}
_exit:
taosArrayDestroy(vAlterTbReq.pMultiTag);
tEncodeSize(tEncodeSVAlterTbRsp, &vAlterTbRsp, pRsp->contLen, ret);
pRsp->pCont = rpcMallocCont(pRsp->contLen);
tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);

View File

@ -519,9 +519,6 @@ int32_t nodesMakeNode(ENodeType type, SNode** ppNodeOut) {
case QUERY_NODE_ALTER_SUPER_TABLE_STMT:
code = makeNode(type, sizeof(SAlterTableStmt), &pNode);
break;
case QUERY_NODE_ALTER_TABLE_MULTI_STMT:
code = makeNode(type, sizeof(SAlterTableMultiStmt), &pNode);
break;
case QUERY_NODE_CREATE_USER_STMT:
code = makeNode(type, sizeof(SCreateUserStmt), &pNode);
break;
@ -1360,13 +1357,15 @@ void nodesDestroyNode(SNode* pNode) {
SAlterTableStmt* pStmt = (SAlterTableStmt*)pNode;
nodesDestroyNode((SNode*)pStmt->pOptions);
nodesDestroyNode((SNode*)pStmt->pVal);
break;
}
case QUERY_NODE_ALTER_TABLE_MULTI_STMT: {
SAlterTableMultiStmt* pStmt = (SAlterTableMultiStmt*)pNode;
// nodesDestroyList(pStmt->pTables);
// nodesDestroyNode((SNode*)pStmt->pOptions);
// nodesDestroyNode((SNode*)pStmt->pVal);
if (pStmt->pNodeListTagValue != NULL) {
SNodeList* pNodeList = pStmt->pNodeListTagValue;
SNode* pSubNode = NULL;
FOREACH(pSubNode, pNodeList) {
SAlterTableStmt* pSubAlterTable = (SAlterTableStmt*)pSubNode;
nodesDestroyNode((SNode*)pSubAlterTable->pOptions);
nodesDestroyNode((SNode*)pSubAlterTable->pVal);
}
}
break;
}
case QUERY_NODE_CREATE_USER_STMT: {

View File

@ -390,14 +390,14 @@ alter_table_clause(A) ::=
full_table_name(B) RENAME TAG column_name(C) column_name(D). { A = createAlterTableRenameCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &C, &D); }
%type column_eq_value_list { SNodeList* }
%destructor column_eq_value_list { nodesDestroyList($$); }
column_eq_value(A) ::= column_name(C) NK_EQ tags_literal(D). { A = createAlterSingleTagColumnNode(pCxt, &C, D); }
column_eq_value_list(A) ::= column_eq_value(B). { A = createNodeList(pCxt, B); }
column_eq_value_list(A) ::= column_eq_value_list(B) NK_COMMA column_eq_value(C). { A = addNodeToList(pCxt, B, C);}
%type column_tag_value_list { SNodeList* }
%destructor column_tag_value_list { nodesDestroyList($$); }
column_tag_value(A) ::= column_name(C) NK_EQ tags_literal(D). { A = createAlterSingleTagColumnNode(pCxt, &C, D); }
column_tag_value_list(A) ::= column_tag_value(B). { A = createNodeList(pCxt, B); }
column_tag_value_list(A) ::= column_tag_value_list(B) NK_COMMA column_tag_value(C). { A = addNodeToList(pCxt, B, C);}
alter_table_clause(A) ::=
full_table_name(B) SET TAG column_eq_value_list(C). { A = createAlterTableSetMultiTagValue(pCxt, B, C); }
full_table_name(B) SET TAG column_tag_value_list(C). { A = createAlterTableSetMultiTagValue(pCxt, B, C); }
%type multi_create_clause { SNodeList* }
%destructor multi_create_clause { nodesDestroyList($$); }

View File

@ -2555,6 +2555,7 @@ SNode* createAlterSingleTagColumnNode(SAstCreateContext* pCtx, SToken* pTagName,
pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_TAG_VAL;
COPY_STRING_FORM_ID_TOKEN(pStmt->colName, pTagName);
pStmt->pVal = (SValueNode*)pVal;
pStmt->pNodeListTagValue = NULL;
return (SNode*)pStmt;
_err:
return NULL;

View File

@ -970,7 +970,6 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
case QUERY_NODE_DROP_SUPER_TABLE_STMT:
return collectMetaKeyFromDropStable(pCxt, (SDropSuperTableStmt*)pStmt);
case QUERY_NODE_ALTER_TABLE_STMT:
case QUERY_NODE_ALTER_TABLE_MULTI_STMT:
return collectMetaKeyFromAlterTable(pCxt, (SAlterTableStmt*)pStmt);
case QUERY_NODE_ALTER_SUPER_TABLE_STMT:
return collectMetaKeyFromAlterStable(pCxt, (SAlterTableStmt*)pStmt);

View File

@ -15184,11 +15184,7 @@ static int32_t rewriteDropSuperTable(STranslateContext* pCxt, SQuery* pQuery) {
static int32_t buildUpdateTagValReqImpl2(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta,
char* colName, SMultiTagUpateVal* pReq) {
int32_t code = TSDB_CODE_SUCCESS;
if (NULL == pReq->tagName) {
return terrno;
}
int32_t code = TSDB_CODE_SUCCESS;
SSchema* pSchema = getTagSchema(pTableMeta, colName);
if (NULL == pSchema) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE, "Invalid tag name: %s", colName);
@ -15360,7 +15356,7 @@ static int32_t buildUpdateMultiTagValReq(STranslateContext* pCxt, SAlterTableStm
return buildUpdateTagValReqImpl(pCxt, head, pTableMeta, head->colName, pReq);
} else {
pReq->pMultiTag = taosArrayInit(nTagValues, sizeof(SMultiTagUpateVal));
if (NULL == pReq->pTagArray) {
if (pReq->pMultiTag == NULL) {
return terrno;
}
@ -15373,7 +15369,9 @@ static int32_t buildUpdateMultiTagValReq(STranslateContext* pCxt, SAlterTableStm
if (TSDB_CODE_SUCCESS != code) {
return code;
}
TAOS_UNUSED(taosArrayPush(pReq->pMultiTag, &val));
if (taosArrayPush(pReq->pMultiTag, &val) == NULL) {
return terrno;
}
}
}
@ -15658,6 +15656,18 @@ static int32_t buildModifyVnodeArray(STranslateContext* pCxt, SAlterTableStmt* p
return code;
}
static void deleTagVal(void* val) {
SMultiTagUpateVal* pTag = val;
taosMemoryFree(pTag->tagName);
for (int i = 0; i < taosArrayGetSize(pTag->pTagArray); ++i) {
STagVal* p = (STagVal*)taosArrayGet(pTag->pTagArray, i);
if (IS_VAR_DATA_TYPE(p->type)) {
taosMemoryFreeClear(p->pData);
}
}
taosArrayDestroy(pTag->pTagArray);
}
static void destoryAlterTbReq(SVAlterTbReq* pReq) {
taosMemoryFree(pReq->tbName);
taosMemoryFree(pReq->colName);
@ -15670,6 +15680,10 @@ static void destoryAlterTbReq(SVAlterTbReq* pReq) {
taosMemoryFreeClear(p->pData);
}
}
if (pReq->action == TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL) {
taosArrayDestroyEx(pReq->pMultiTag, deleTagVal);
}
taosArrayDestroy(pReq->pTagArray);
if (pReq->tagFree) tTagFree((STag*)pReq->pTagVal);
}
@ -16374,7 +16388,6 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
case QUERY_NODE_DROP_SUPER_TABLE_STMT:
code = rewriteDropSuperTable(pCxt, pQuery);
break;
case QUERY_NODE_ALTER_TABLE_MULTI_STMT:
case QUERY_NODE_ALTER_TABLE_STMT:
code = rewriteAlterTable(pCxt, pQuery);
break;