fix: plannerTest/parserTest crash and memory leaks

This commit is contained in:
wangjiaming0909 2024-02-02 15:04:11 +08:00
parent ecdcc6dee1
commit 573fdfbbfd
7 changed files with 25 additions and 4 deletions

View File

@ -4446,7 +4446,7 @@ static int32_t findVgroupsFromEqualTbname(STranslateContext* pCxt, SEqCondTbName
SName snameTb;
char* tbName = taosArrayGetP(pInfo->aTbnames, j);
toName(pCxt->pParseCxt->acctId, dbName, tbName, &snameTb);
SVgroupInfo vgInfo;
SVgroupInfo vgInfo = {0};
bool bExists;
int32_t code = catalogGetCachedTableHashVgroup(pCxt->pParseCxt->pCatalog, &snameTb, &vgInfo, &bExists);
if (code == TSDB_CODE_SUCCESS && bExists) {
@ -8217,13 +8217,13 @@ static int32_t createLastTsSelectStmt(char* pDb, char* pTable, STableMeta* pMeta
return TSDB_CODE_OUT_OF_MEMORY;
}
code = nodesListAppend(pNode1->pParameterList, (SNode*)pFunc1);
code = nodesListStrictAppend(pNode1->pParameterList, nodesCloneNode((SNode*)pFunc1));
if (code) {
nodesDestroyNode((SNode*)pNode1);
return code;
}
code = nodesListAppend((*pSelect1)->pGroupByList, nodesCloneNode((const SNode*)pNode1));
code = nodesListAppend((*pSelect1)->pGroupByList, (SNode*)pNode1);
if (code) {
return code;
}
@ -8240,7 +8240,7 @@ static int32_t createLastTsSelectStmt(char* pDb, char* pTable, STableMeta* pMeta
return TSDB_CODE_OUT_OF_MEMORY;
}
code = nodesListAppend(pNode2->pParameterList, nodesCloneNode((const SNode*)pFunc2));
code = nodesListStrictAppend(pNode2->pParameterList, nodesCloneNode((SNode*)pFunc2));
if (code) {
nodesDestroyNode((SNode*)pNode2);
return code;

View File

@ -755,6 +755,7 @@ void MockCatalogService::destoryCatalogReq(SCatalogReq* pReq) {
taosArrayDestroy(pReq->pUser);
taosArrayDestroy(pReq->pTableIndex);
taosArrayDestroy(pReq->pTableCfg);
taosArrayDestroyEx(pReq->pView, destoryTablesReq);
delete pReq;
}
@ -781,6 +782,7 @@ void MockCatalogService::destoryMetaData(SMetaData* pData) {
taosArrayDestroyEx(pData->pQnodeList, destoryMetaRes);
taosArrayDestroyEx(pData->pTableCfg, destoryMetaRes);
taosArrayDestroyEx(pData->pDnodeList, destoryMetaArrayRes);
taosArrayDestroyEx(pData->pView, destoryMetaRes);
taosMemoryFree(pData->pSvrVer);
delete pData;
}

View File

@ -73,6 +73,7 @@ TEST_F(ParserInitialATest, alterDnode) {
ASSERT_EQ(req.dnodeId, expect.dnodeId);
ASSERT_EQ(std::string(req.config), std::string(expect.config));
ASSERT_EQ(std::string(req.value), std::string(expect.value));
tFreeSMCfgDnodeReq(&req);
});
setCfgDnodeReq(1, "resetLog");
@ -183,6 +184,7 @@ TEST_F(ParserInitialATest, alterDatabase) {
ASSERT_EQ(req.minRows, expect.minRows);
ASSERT_EQ(req.walRetentionPeriod, expect.walRetentionPeriod);
ASSERT_EQ(req.walRetentionSize, expect.walRetentionSize);
tFreeSAlterDbReq(&req);
});
const int32_t MINUTE_PER_DAY = MILLISECOND_PER_DAY / MILLISECOND_PER_MINUTE;
@ -827,6 +829,7 @@ TEST_F(ParserInitialATest, alterUser) {
ASSERT_EQ(std::string(req.user), std::string(expect.user));
ASSERT_EQ(std::string(req.pass), std::string(expect.pass));
ASSERT_EQ(std::string(req.objname), std::string(expect.objname));
tFreeSAlterUserReq(&req);
});
setAlterUserReq("wxy", TSDB_ALTER_USER_PASSWD, "123456");
@ -853,6 +856,7 @@ TEST_F(ParserInitialATest, balanceVgroup) {
ASSERT_EQ(pQuery->pCmdMsg->msgType, TDMT_MND_BALANCE_VGROUP);
SBalanceVgroupReq req = {0};
ASSERT_EQ(tDeserializeSBalanceVgroupReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req), TSDB_CODE_SUCCESS);
tFreeSBalanceVgroupReq(&req);
});
run("BALANCE VGROUP");
@ -870,6 +874,7 @@ TEST_F(ParserInitialATest, balanceVgroupLeader) {
SBalanceVgroupLeaderReq req = {0};
ASSERT_EQ(tDeserializeSBalanceVgroupLeaderReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req),
TSDB_CODE_SUCCESS);
tFreeSBalanceVgroupLeaderReq(&req);
});
run("BALANCE VGROUP LEADER");

View File

@ -52,6 +52,7 @@ TEST_F(ParserExplainToSyncdbTest, grant) {
ASSERT_EQ(req.alterType, expect.alterType);
ASSERT_EQ(string(req.user), string(expect.user));
ASSERT_EQ(string(req.objname), string(expect.objname));
tFreeSAlterUserReq(&req);
});
setAlterUserReq(TSDB_ALTER_USER_ADD_PRIVILEGES, PRIVILEGE_TYPE_ALL, "wxy", "0.*");
@ -183,6 +184,7 @@ TEST_F(ParserExplainToSyncdbTest, redistributeVgroup) {
ASSERT_EQ(req.dnodeId1, expect.dnodeId1);
ASSERT_EQ(req.dnodeId2, expect.dnodeId2);
ASSERT_EQ(req.dnodeId3, expect.dnodeId3);
tFreeSRedistributeVgroupReq(&req);
});
setRedistributeVgroupReqFunc(3, 1);
@ -228,6 +230,7 @@ TEST_F(ParserExplainToSyncdbTest, restoreDnode) {
ASSERT_EQ(tDeserializeSRestoreDnodeReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req), TSDB_CODE_SUCCESS);
ASSERT_EQ(req.dnodeId, expect.dnodeId);
ASSERT_EQ(req.restoreType, expect.restoreType);
tFreeSRestoreDnodeReq(&req);
});
setRestoreDnodeReq(1, RESTORE_TYPE__ALL);
@ -272,6 +275,7 @@ TEST_F(ParserExplainToSyncdbTest, revoke) {
ASSERT_EQ(req.alterType, expect.alterType);
ASSERT_EQ(string(req.user), string(expect.user));
ASSERT_EQ(string(req.objname), string(expect.objname));
tFreeSAlterUserReq(&req);
});
setAlterUserReq(TSDB_ALTER_USER_DEL_PRIVILEGES, PRIVILEGE_TYPE_ALL, "wxy", "0.*");

View File

@ -43,6 +43,7 @@ TEST_F(ParserInitialCTest, compact) {
ASSERT_EQ(std::string(req.db), std::string(expect.db));
ASSERT_EQ(req.timeRange.skey, expect.timeRange.skey);
ASSERT_EQ(req.timeRange.ekey, expect.timeRange.ekey);
tFreeSCompactDbReq(&req);
});
setCompactDbReq("test");
@ -374,6 +375,7 @@ TEST_F(ParserInitialCTest, createDnode) {
ASSERT_EQ(std::string(req.fqdn), std::string(expect.fqdn));
ASSERT_EQ(req.port, expect.port);
tFreeSCreateDnodeReq(&req);
});
setCreateDnodeReq("abc1", 7030);
@ -599,6 +601,7 @@ TEST_F(ParserInitialCTest, createMnode) {
tDeserializeSCreateDropMQSNodeReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req));
ASSERT_EQ(req.dnodeId, expect.dnodeId);
tFreeSMCreateQnodeReq(&req);
});
setCreateMnodeReq(1);
@ -622,6 +625,7 @@ TEST_F(ParserInitialCTest, createQnode) {
tDeserializeSCreateDropMQSNodeReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req));
ASSERT_EQ(req.dnodeId, expect.dnodeId);
tFreeSMCreateQnodeReq(&req);
});
setCreateQnodeReq(1);
@ -1326,6 +1330,7 @@ TEST_F(ParserInitialCTest, createUser) {
ASSERT_EQ(req.enable, expect.enable);
ASSERT_EQ(std::string(req.user), std::string(expect.user));
ASSERT_EQ(std::string(req.pass), std::string(expect.pass));
tFreeSCreateUserReq(&req);
});
setCreateUserReq("wxy", "123456");

View File

@ -117,6 +117,7 @@ TEST_F(ParserInitialDTest, dropDnode) {
ASSERT_EQ(req.port, expect.port);
ASSERT_EQ(req.force, expect.force);
ASSERT_EQ(req.unsafe, expect.unsafe);
tFreeSDropDnodeReq(&req);
});
setDropDnodeReqById(1);
@ -208,6 +209,7 @@ TEST_F(ParserInitialDTest, dropQnode) {
tDeserializeSCreateDropMQSNodeReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req));
ASSERT_EQ(req.dnodeId, expect.dnodeId);
tFreeSDDropQnodeReq(&req);
});
setDropQnodeReq(1);
@ -245,6 +247,7 @@ TEST_F(ParserInitialDTest, dropStream) {
ASSERT_EQ(std::string(req.name), std::string(expect.name));
ASSERT_EQ(req.igNotExists, expect.igNotExists);
tFreeMDropStreamReq(&req);
});
setDropStreamReq("s1");
@ -285,6 +288,7 @@ TEST_F(ParserInitialDTest, dropUser) {
ASSERT_TRUE(TSDB_CODE_SUCCESS == tDeserializeSDropUserReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req));
ASSERT_EQ(std::string(req.user), std::string(expect.user));
tFreeSDropUserReq(&req);
});
setDropUserReq("wxy");

View File

@ -2977,6 +2977,7 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
}
nodesClearList(cxt.pLastCols);
}
nodesClearList(cxt.pOtherCols);
pAgg->hasLastRow = false;
pAgg->hasLast = false;