未验证 提交 aa9a300a 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #2350 from taosdata/hotfix/crash

[TD-543] coverity scan
...@@ -960,6 +960,8 @@ static int32_t mnodeProcessAlterDbMsg(SMnodeMsg *pMsg) { ...@@ -960,6 +960,8 @@ static int32_t mnodeProcessAlterDbMsg(SMnodeMsg *pMsg) {
} }
static int32_t mnodeDropDb(SMnodeMsg *pMsg) { static int32_t mnodeDropDb(SMnodeMsg *pMsg) {
if (pMsg == NULL) return TSDB_CODE_MND_APP_ERROR;
SDbObj *pDb = pMsg->pDb; SDbObj *pDb = pMsg->pDb;
mPrint("db:%s, drop db from sdb", pDb->name); mPrint("db:%s, drop db from sdb", pDb->name);
...@@ -973,7 +975,7 @@ static int32_t mnodeDropDb(SMnodeMsg *pMsg) { ...@@ -973,7 +975,7 @@ static int32_t mnodeDropDb(SMnodeMsg *pMsg) {
int32_t code = sdbDeleteRow(&oper); int32_t code = sdbDeleteRow(&oper);
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
mLPrint("db:%s, is dropped by %s", pDb->name, mnodeGetUserFromMsg(pMsg)); mLPrint("db:%s, is dropped by %s", pDb->name, mnodeGetUserFromMsg(pMsg));
if (pMsg != NULL) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
} }
return code; return code;
......
...@@ -90,11 +90,12 @@ static int32_t mnodeDnodeActionDelete(SSdbOper *pOper) { ...@@ -90,11 +90,12 @@ static int32_t mnodeDnodeActionDelete(SSdbOper *pOper) {
static int32_t mnodeDnodeActionUpdate(SSdbOper *pOper) { static int32_t mnodeDnodeActionUpdate(SSdbOper *pOper) {
SDnodeObj *pDnode = pOper->pObj; SDnodeObj *pDnode = pOper->pObj;
SDnodeObj *pSaved = mnodeGetDnode(pDnode->dnodeId); SDnodeObj *pSaved = mnodeGetDnode(pDnode->dnodeId);
if (pDnode != pSaved && pDnode != NULL && pSaved != NULL) { if (pSaved != NULL && pDnode != pSaved) {
memcpy(pSaved, pDnode, pOper->rowSize); memcpy(pSaved, pDnode, pOper->rowSize);
free(pDnode); free(pDnode);
mnodeDecDnodeRef(pSaved);
} }
mnodeDecDnodeRef(pSaved);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -120,8 +121,10 @@ static int32_t mnodeDnodeActionRestored() { ...@@ -120,8 +121,10 @@ static int32_t mnodeDnodeActionRestored() {
mPrint("dnode first deploy, create dnode:%s", tsLocalEp); mPrint("dnode first deploy, create dnode:%s", tsLocalEp);
mnodeCreateDnode(tsLocalEp, NULL); mnodeCreateDnode(tsLocalEp, NULL);
SDnodeObj *pDnode = mnodeGetDnodeByEp(tsLocalEp); SDnodeObj *pDnode = mnodeGetDnodeByEp(tsLocalEp);
mnodeAddMnode(pDnode->dnodeId); if (pDnode != NULL) {
mnodeDecDnodeRef(pDnode); mnodeAddMnode(pDnode->dnodeId);
mnodeDecDnodeRef(pDnode);
}
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -371,6 +374,7 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { ...@@ -371,6 +374,7 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
bool ret = mnodeCheckClusterCfgPara(&(pStatus->clusterCfg)); bool ret = mnodeCheckClusterCfgPara(&(pStatus->clusterCfg));
if (false == ret) { if (false == ret) {
mnodeDecDnodeRef(pDnode); mnodeDecDnodeRef(pDnode);
rpcFreeCont(pRsp);
mError("dnode %s cluster cfg parameters inconsistent", pStatus->dnodeEp); mError("dnode %s cluster cfg parameters inconsistent", pStatus->dnodeEp);
return TSDB_CODE_MND_CLUSTER_CFG_INCONSISTENT; return TSDB_CODE_MND_CLUSTER_CFG_INCONSISTENT;
} }
......
...@@ -122,7 +122,7 @@ static int32_t mnodeProcessShowMsg(SMnodeMsg *pMsg) { ...@@ -122,7 +122,7 @@ static int32_t mnodeProcessShowMsg(SMnodeMsg *pMsg) {
SShowObj *pShow = (SShowObj *) calloc(1, showObjSize); SShowObj *pShow = (SShowObj *) calloc(1, showObjSize);
pShow->type = pShowMsg->type; pShow->type = pShowMsg->type;
pShow->payloadLen = htons(pShowMsg->payloadLen); pShow->payloadLen = htons(pShowMsg->payloadLen);
strcpy(pShow->db, pShowMsg->db); tstrncpy(pShow->db, pShowMsg->db, TSDB_DB_NAME_LEN);
memcpy(pShow->payload, pShowMsg->payload, pShow->payloadLen); memcpy(pShow->payload, pShowMsg->payload, pShow->payloadLen);
pShow = mnodePutShowObj(pShow, showObjSize); pShow = mnodePutShowObj(pShow, showObjSize);
......
...@@ -443,7 +443,7 @@ static int32_t mnodeSuperTableActionDelete(SSdbOper *pOper) { ...@@ -443,7 +443,7 @@ static int32_t mnodeSuperTableActionDelete(SSdbOper *pOper) {
static int32_t mnodeSuperTableActionUpdate(SSdbOper *pOper) { static int32_t mnodeSuperTableActionUpdate(SSdbOper *pOper) {
SSuperTableObj *pNew = pOper->pObj; SSuperTableObj *pNew = pOper->pObj;
SSuperTableObj *pTable = mnodeGetSuperTable(pNew->info.tableId); SSuperTableObj *pTable = mnodeGetSuperTable(pNew->info.tableId);
if (pTable != pNew) { if (pTable != NULL && pTable != pNew) {
void *oldTableId = pTable->info.tableId; void *oldTableId = pTable->info.tableId;
void *oldSchema = pTable->schema; void *oldSchema = pTable->schema;
void *oldVgHash = pTable->vgHash; void *oldVgHash = pTable->vgHash;
...@@ -457,8 +457,10 @@ static int32_t mnodeSuperTableActionUpdate(SSdbOper *pOper) { ...@@ -457,8 +457,10 @@ static int32_t mnodeSuperTableActionUpdate(SSdbOper *pOper) {
free(pNew); free(pNew);
free(oldTableId); free(oldTableId);
free(oldSchema); free(oldSchema);
mnodeDecTableRef(pTable);
} }
mnodeDecTableRef(pTable);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -779,6 +781,8 @@ static int32_t mnodeProcessTableMetaMsg(SMnodeMsg *pMsg) { ...@@ -779,6 +781,8 @@ static int32_t mnodeProcessTableMetaMsg(SMnodeMsg *pMsg) {
} }
static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
if (pMsg == NULL) return TSDB_CODE_MND_APP_ERROR;
SCMCreateTableMsg *pCreate = pMsg->rpcMsg.pCont; SCMCreateTableMsg *pCreate = pMsg->rpcMsg.pCont;
SSuperTableObj * pStable = calloc(1, sizeof(SSuperTableObj)); SSuperTableObj * pStable = calloc(1, sizeof(SSuperTableObj));
if (pStable == NULL) { if (pStable == NULL) {
...@@ -830,13 +834,15 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { ...@@ -830,13 +834,15 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
} else { } else {
mLPrint("app:%p:%p, table:%s, is created, tags:%d fields:%d", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId, mLPrint("app:%p:%p, table:%s, is created, tags:%d fields:%d", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId,
pStable->numOfTags, pStable->numOfColumns); pStable->numOfTags, pStable->numOfColumns);
if (pMsg != NULL) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
} }
return code; return code;
} }
static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) {
if (pMsg == NULL) return TSDB_CODE_MND_APP_ERROR;
SSuperTableObj *pStable = (SSuperTableObj *)pMsg->pTable; SSuperTableObj *pStable = (SSuperTableObj *)pMsg->pTable;
if (pStable->numOfTables != 0) { if (pStable->numOfTables != 0) {
SHashMutableIterator *pIter = taosHashCreateIter(pStable->vgHash); SHashMutableIterator *pIter = taosHashCreateIter(pStable->vgHash);
...@@ -873,7 +879,7 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) { ...@@ -873,7 +879,7 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) {
int32_t code = sdbDeleteRow(&oper); int32_t code = sdbDeleteRow(&oper);
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
mLPrint("stable:%s, is dropped from sdb, result:%s", pStable->info.tableId, tstrerror(code)); mLPrint("stable:%s, is dropped from sdb, result:%s", pStable->info.tableId, tstrerror(code));
if (pMsg != NULL) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
} }
return code; return code;
...@@ -1418,7 +1424,7 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) { ...@@ -1418,7 +1424,7 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
SDnodeObj *pDnode = pVgroup->vnodeGid[vn].pDnode; SDnodeObj *pDnode = pVgroup->vnodeGid[vn].pDnode;
if (pDnode == NULL) break; if (pDnode == NULL) break;
strncpy(pVgroupInfo->vgroups[vgSize].ipAddr[vn].fqdn, pDnode->dnodeFqdn, tListLen(pDnode->dnodeFqdn)); tstrncpy(pVgroupInfo->vgroups[vgSize].ipAddr[vn].fqdn, pDnode->dnodeFqdn, TSDB_FQDN_LEN);
pVgroupInfo->vgroups[vgSize].ipAddr[vn].port = htons(pDnode->dnodePort); pVgroupInfo->vgroups[vgSize].ipAddr[vn].port = htons(pDnode->dnodePort);
pVgroupInfo->vgroups[vgSize].numOfIps++; pVgroupInfo->vgroups[vgSize].numOfIps++;
...@@ -1462,10 +1468,10 @@ static void *mnodeBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SChildTableO ...@@ -1462,10 +1468,10 @@ static void *mnodeBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SChildTableO
int32_t contLen = 0; int32_t contLen = 0;
if (pTable->info.type == TSDB_CHILD_TABLE) { if (pTable->info.type == TSDB_CHILD_TABLE) {
totalCols = pTable->superTable->numOfColumns + pTable->superTable->numOfTags; totalCols = pTable->superTable->numOfColumns + pTable->superTable->numOfTags;
contLen = sizeof(SMDCreateTableMsg) + totalCols * sizeof(SSchema) + tagDataLen + pTable->sqlLen; contLen = sizeof(SMDCreateTableMsg) + totalCols * sizeof(SSchema) + pTable->sqlLen;
if (pMsg != NULL) { if (pMsg != NULL) {
pTagData = (STagData *)pMsg->schema; pTagData = (STagData *)pMsg->schema;
tagDataLen = ntohl(pTagData->dataLen); tagDataLen = htonl(pTagData->dataLen);
contLen += tagDataLen; contLen += tagDataLen;
} }
} else { } else {
...@@ -1714,7 +1720,7 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { ...@@ -1714,7 +1720,7 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) {
return TSDB_CODE_MND_OUT_OF_MEMORY; return TSDB_CODE_MND_OUT_OF_MEMORY;
} }
strcpy(pDrop->tableId, pTable->info.tableId); tstrncpy(pDrop->tableId, pTable->info.tableId, TSDB_TABLE_ID_LEN);
pDrop->vgId = htonl(pTable->vgId); pDrop->vgId = htonl(pTable->vgId);
pDrop->contLen = htonl(sizeof(SMDDropTableMsg)); pDrop->contLen = htonl(sizeof(SMDDropTableMsg));
pDrop->sid = htonl(pTable->sid); pDrop->sid = htonl(pTable->sid);
...@@ -1873,7 +1879,7 @@ static int32_t mnodeDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) { ...@@ -1873,7 +1879,7 @@ static int32_t mnodeDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) {
pMeta->sid = htonl(pTable->sid); pMeta->sid = htonl(pTable->sid);
pMeta->precision = pDb->cfg.precision; pMeta->precision = pDb->cfg.precision;
pMeta->tableType = pTable->info.type; pMeta->tableType = pTable->info.type;
strncpy(pMeta->tableId, pTable->info.tableId, strlen(pTable->info.tableId)); tstrncpy(pMeta->tableId, pTable->info.tableId, TSDB_TABLE_ID_LEN);
if (pTable->info.type == TSDB_CHILD_TABLE) { if (pTable->info.type == TSDB_CHILD_TABLE) {
pMeta->sversion = htons(pTable->superTable->sversion); pMeta->sversion = htons(pTable->superTable->sversion);
...@@ -1916,7 +1922,7 @@ static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) { ...@@ -1916,7 +1922,7 @@ static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) {
SCMTableInfoMsg *pInfo = pMsg->rpcMsg.pCont; SCMTableInfoMsg *pInfo = pMsg->rpcMsg.pCont;
STagData *pTag = (STagData *)pInfo->tags; STagData *pTag = (STagData *)pInfo->tags;
int32_t contLen = sizeof(SCMCreateTableMsg) + offsetof(STagData, data) + ntohl(pTag->dataLen); int32_t contLen = sizeof(SCMCreateTableMsg) + offsetof(STagData, data) + htonl(pTag->dataLen);
SCMCreateTableMsg *pCreateMsg = rpcMallocCont(contLen); SCMCreateTableMsg *pCreateMsg = rpcMallocCont(contLen);
if (pCreateMsg == NULL) { if (pCreateMsg == NULL) {
mError("app:%p:%p, table:%s, failed to create table while get meta info, no enough memory", pMsg->rpcMsg.ahandle, mError("app:%p:%p, table:%s, failed to create table while get meta info, no enough memory", pMsg->rpcMsg.ahandle,
...@@ -2380,8 +2386,7 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) { ...@@ -2380,8 +2386,7 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) {
if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pAlter->tableId); if (pMsg->pTable == NULL) pMsg->pTable = mnodeGetTable(pAlter->tableId);
if (pMsg->pTable == NULL) { if (pMsg->pTable == NULL) {
mError("app:%p:%p, table:%s, failed to alter table, table not exist", pMsg->rpcMsg.ahandle, pMsg, mError("app:%p:%p, table:%s, failed to alter table, table not exist", pMsg->rpcMsg.ahandle, pMsg, pAlter->tableId);
pMsg->pTable->tableId);
return TSDB_CODE_MND_INVALID_TABLE_NAME; return TSDB_CODE_MND_INVALID_TABLE_NAME;
} }
......
...@@ -216,7 +216,7 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) { ...@@ -216,7 +216,7 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) {
} }
pUser = calloc(1, sizeof(SUserObj)); pUser = calloc(1, sizeof(SUserObj));
strcpy(pUser->user, name); tstrncpy(pUser->user, name, TSDB_USER_LEN);
taosEncryptPass((uint8_t*) pass, strlen(pass), pUser->pass); taosEncryptPass((uint8_t*) pass, strlen(pass), pUser->pass);
strcpy(pUser->acct, pAcct->user); strcpy(pUser->acct, pAcct->user);
pUser->createdTime = taosGetTimestampMs(); pUser->createdTime = taosGetTimestampMs();
...@@ -368,7 +368,7 @@ SUserObj *mnodeGetUserFromConn(void *pConn) { ...@@ -368,7 +368,7 @@ SUserObj *mnodeGetUserFromConn(void *pConn) {
char *mnodeGetUserFromMsg(void *pMsg) { char *mnodeGetUserFromMsg(void *pMsg) {
SMnodeMsg *pMnodeMsg = pMsg; SMnodeMsg *pMnodeMsg = pMsg;
if (pMnodeMsg != NULL &&pMnodeMsg->pUser != NULL) { if (pMnodeMsg != NULL && pMnodeMsg->pUser != NULL) {
return pMnodeMsg->pUser->user; return pMnodeMsg->pUser->user;
} else { } else {
return "system"; return "system";
......
...@@ -133,7 +133,7 @@ static void mnodeVgroupUpdateIdPool(SVgObj *pVgroup) { ...@@ -133,7 +133,7 @@ static void mnodeVgroupUpdateIdPool(SVgObj *pVgroup) {
taosUpdateIdPool(pVgroup->idPool, pDb->cfg.maxTables); taosUpdateIdPool(pVgroup->idPool, pDb->cfg.maxTables);
int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxTables; int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxTables;
pVgroup->tableList = (SChildTableObj **)realloc(pVgroup->tableList, size); pVgroup->tableList = (SChildTableObj **)realloc(pVgroup->tableList, size);
memset(pVgroup->tableList + oldTables, 0, (pDb->cfg.maxTables - oldTables) * sizeof(SChildTableObj **)); memset(pVgroup->tableList + oldTables, 0, (pDb->cfg.maxTables - oldTables) * sizeof(SChildTableObj *));
} }
} }
} }
...@@ -252,7 +252,9 @@ void mnodeUpdateVgroup(SVgObj *pVgroup) { ...@@ -252,7 +252,9 @@ void mnodeUpdateVgroup(SVgObj *pVgroup) {
.pObj = pVgroup .pObj = pVgroup
}; };
sdbUpdateRow(&oper); if (sdbUpdateRow(&oper) != TSDB_CODE_SUCCESS) {
mError("vgId:%d, failed to update vgroup", pVgroup->vgId);
}
mnodeSendCreateVgroupMsg(pVgroup, NULL); mnodeSendCreateVgroupMsg(pVgroup, NULL);
} }
...@@ -323,8 +325,10 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) { ...@@ -323,8 +325,10 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) {
} }
int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) { int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) {
if (pMsg == NULL) return TSDB_CODE_MND_APP_ERROR;
SVgObj *pVgroup = (SVgObj *)calloc(1, sizeof(SVgObj)); SVgObj *pVgroup = (SVgObj *)calloc(1, sizeof(SVgObj));
strcpy(pVgroup->dbName, pDb->name); tstrncpy(pVgroup->dbName, pDb->name, TSDB_DB_NAME_LEN);
pVgroup->numOfVnodes = pDb->cfg.replications; pVgroup->numOfVnodes = pDb->cfg.replications;
pVgroup->createdTime = taosGetTimestampMs(); pVgroup->createdTime = taosGetTimestampMs();
pVgroup->accessState = TSDB_VN_ALL_ACCCESS; pVgroup->accessState = TSDB_VN_ALL_ACCCESS;
...@@ -350,7 +354,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) { ...@@ -350,7 +354,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) {
pMsg->pVgroup = NULL; pMsg->pVgroup = NULL;
tfree(pVgroup); tfree(pVgroup);
} else { } else {
if (pMsg != NULL) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
} }
return code; return code;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册