From 280c5d4b3db4acebba17b5a7428c3e13ffdab6f6 Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 22 Jul 2024 16:33:42 +0800 Subject: [PATCH] enh: return error code --- source/dnode/mnode/impl/src/mndAcct.c | 4 ++ source/dnode/mnode/impl/src/mndArbGroup.c | 4 ++ source/dnode/mnode/impl/src/mndCluster.c | 4 ++ source/dnode/mnode/impl/src/mndCompact.c | 4 ++ .../dnode/mnode/impl/src/mndCompactDetail.c | 10 +++-- source/dnode/mnode/impl/src/mndConsumer.c | 4 ++ source/dnode/mnode/impl/src/mndDb.c | 4 ++ source/dnode/mnode/impl/src/mndDnode.c | 4 ++ source/dnode/mnode/impl/src/mndFunc.c | 4 ++ source/dnode/mnode/impl/src/mndIndex.c | 4 ++ source/dnode/mnode/impl/src/mndMnode.c | 4 ++ source/dnode/mnode/impl/src/mndQnode.c | 4 ++ source/dnode/mnode/impl/src/mndSma.c | 4 ++ source/dnode/mnode/impl/src/mndSnode.c | 4 ++ source/dnode/mnode/impl/src/mndStb.c | 4 ++ source/dnode/mnode/impl/src/mndStream.c | 2 + source/dnode/mnode/impl/src/mndStreamTrans.c | 2 + source/dnode/mnode/impl/src/mndSubscribe.c | 4 ++ source/dnode/mnode/impl/src/mndTopic.c | 4 ++ source/dnode/mnode/impl/src/mndTrans.c | 9 +++- source/dnode/mnode/impl/src/mndUser.c | 40 +++++++++++------ source/dnode/mnode/impl/src/mndVgroup.c | 4 ++ source/dnode/mnode/sdb/inc/sdb.h | 43 +++++++++++-------- 23 files changed, 138 insertions(+), 36 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index 99f545ba74..425624d717 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -113,6 +113,8 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) { } static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRaw *pRaw = sdbAllocRaw(SDB_ACCT, ACCT_VER_NUMBER, sizeof(SAcctObj) + ACCT_RESERVE_SIZE); @@ -153,6 +155,8 @@ _OVER: } static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SAcctObj *pAcct = NULL; SSdbRow *pRow = NULL; diff --git a/source/dnode/mnode/impl/src/mndArbGroup.c b/source/dnode/mnode/impl/src/mndArbGroup.c index c3c150ba50..2adb420abe 100644 --- a/source/dnode/mnode/impl/src/mndArbGroup.c +++ b/source/dnode/mnode/impl/src/mndArbGroup.c @@ -114,6 +114,8 @@ void mndArbGroupInitFromVgObj(SVgObj *pVgObj, SArbGroup *outGroup) { } SSdbRaw *mndArbGroupActionEncode(SArbGroup *pGroup) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; int32_t size = sizeof(SArbGroup) + ARBGROUP_RESERVE_SIZE; @@ -152,6 +154,8 @@ _OVER: } SSdbRow *mndArbGroupActionDecode(SSdbRaw *pRaw) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRow *pRow = NULL; SArbGroup *pGroup = NULL; diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index 47f289dcfd..366e4543fe 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -144,6 +144,8 @@ int64_t mndGetClusterUpTime(SMnode *pMnode) { } static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRaw *pRaw = sdbAllocRaw(SDB_CLUSTER, CLUSTER_VER_NUMBE, sizeof(SClusterObj) + CLUSTER_RESERVE_SIZE); @@ -172,6 +174,8 @@ _OVER: } static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SClusterObj *pCluster = NULL; SSdbRow *pRow = NULL; diff --git a/source/dnode/mnode/impl/src/mndCompact.c b/source/dnode/mnode/impl/src/mndCompact.c index 065a9a327d..cdb4680ad6 100644 --- a/source/dnode/mnode/impl/src/mndCompact.c +++ b/source/dnode/mnode/impl/src/mndCompact.c @@ -88,6 +88,8 @@ int32_t tDeserializeSCompactObj(void *buf, int32_t bufLen, SCompactObj *pObj) { } SSdbRaw *mndCompactActionEncode(SCompactObj *pCompact) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_SUCCESS; void *buf = NULL; @@ -136,6 +138,8 @@ OVER: } SSdbRow *mndCompactActionDecode(SSdbRaw *pRaw) { + int32_t code = 0; + int32_t lino = 0; SSdbRow *pRow = NULL; SCompactObj *pCompact = NULL; void *buf = NULL; diff --git a/source/dnode/mnode/impl/src/mndCompactDetail.c b/source/dnode/mnode/impl/src/mndCompactDetail.c index 7d73cf8dcd..c68fbfac2d 100644 --- a/source/dnode/mnode/impl/src/mndCompactDetail.c +++ b/source/dnode/mnode/impl/src/mndCompactDetail.c @@ -144,6 +144,8 @@ int32_t tDeserializeSCompactDetailObj(void *buf, int32_t bufLen, SCompactDetailO } SSdbRaw *mndCompactDetailActionEncode(SCompactDetailObj *pCompact) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_SUCCESS; void *buf = NULL; @@ -193,9 +195,11 @@ OVER: } SSdbRow *mndCompactDetailActionDecode(SSdbRaw *pRaw) { - SSdbRow *pRow = NULL; - SCompactDetailObj *pCompact = NULL; - void *buf = NULL; + int32_t code = 0; + int32_t lino = 0; + SSdbRow *pRow = NULL; + SCompactDetailObj *pCompact = NULL; + void *buf = NULL; terrno = TSDB_CODE_SUCCESS; int8_t sver = 0; diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index 7788bf005a..384bfb6747 100644 --- a/source/dnode/mnode/impl/src/mndConsumer.c +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -700,6 +700,8 @@ _over: } SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; void *buf = NULL; @@ -736,6 +738,8 @@ CM_ENCODE_OVER: } SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw) { + int32_t code = 0; + int32_t lino = 0; SSdbRow *pRow = NULL; SMqConsumerObj *pConsumer = NULL; void *buf = NULL; diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 1c9be5cf81..da041bc0dd 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -88,6 +88,8 @@ int32_t mndInitDb(SMnode *pMnode) { void mndCleanupDb(SMnode *pMnode) {} SSdbRaw *mndDbActionEncode(SDbObj *pDb) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; int32_t size = sizeof(SDbObj) + pDb->cfg.numOfRetensions * sizeof(SRetention) + DB_RESERVE_SIZE; @@ -166,6 +168,8 @@ _OVER: } static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRow *pRow = NULL; SDbObj *pDb = NULL; diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 879f533635..c49c295234 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -184,6 +184,8 @@ _OVER: } static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRaw *pRaw = sdbAllocRaw(SDB_DNODE, TSDB_DNODE_VER_NUMBER, sizeof(SDnodeObj) + TSDB_DNODE_RESERVE_SIZE); @@ -215,6 +217,8 @@ _OVER: } static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRow *pRow = NULL; SDnodeObj *pDnode = NULL; diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index 333fdf83bb..ffbfc7fef7 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -61,6 +61,8 @@ int32_t mndInitFunc(SMnode *pMnode) { void mndCleanupFunc(SMnode *pMnode) {} static SSdbRaw *mndFuncActionEncode(SFuncObj *pFunc) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; int32_t size = pFunc->commentSize + pFunc->codeSize + sizeof(SFuncObj) + SDB_FUNC_RESERVE_SIZE; @@ -101,6 +103,8 @@ _OVER: } static SSdbRow *mndFuncActionDecode(SSdbRaw *pRaw) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRow *pRow = NULL; SFuncObj *pFunc = NULL; diff --git a/source/dnode/mnode/impl/src/mndIndex.c b/source/dnode/mnode/impl/src/mndIndex.c index bb77f6c69b..acb8a23756 100644 --- a/source/dnode/mnode/impl/src/mndIndex.c +++ b/source/dnode/mnode/impl/src/mndIndex.c @@ -207,6 +207,8 @@ void mndCleanupIdx(SMnode *pMnode) { } static SSdbRaw *mndIdxActionEncode(SIdxObj *pIdx) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; // int32_t size = @@ -244,6 +246,8 @@ _OVER: } static SSdbRow *mndIdxActionDecode(SSdbRaw *pRaw) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRow *pRow = NULL; SIdxObj *pIdx = NULL; diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index 7b1ca9c625..014d6468ff 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -127,6 +127,8 @@ static int32_t mndCreateDefaultMnode(SMnode *pMnode) { } static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pObj) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRaw *pRaw = sdbAllocRaw(SDB_MNODE, MNODE_VER_NUMBER, sizeof(SMnodeObj) + MNODE_RESERVE_SIZE); @@ -154,6 +156,8 @@ _OVER: } static SSdbRow *mndMnodeActionDecode(SSdbRaw *pRaw) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRow *pRow = NULL; SMnodeObj *pObj = NULL; diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index 6cf0fbd387..d6647f88f2 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -75,6 +75,8 @@ void mndReleaseQnode(SMnode *pMnode, SQnodeObj *pObj) { } static SSdbRaw *mndQnodeActionEncode(SQnodeObj *pObj) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRaw *pRaw = sdbAllocRaw(SDB_QNODE, QNODE_VER_NUMBER, sizeof(SQnodeObj) + QNODE_RESERVE_SIZE); @@ -100,6 +102,8 @@ _OVER: } static SSdbRow *mndQnodeActionDecode(SSdbRaw *pRaw) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRow *pRow = NULL; SQnodeObj *pObj = NULL; diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index 946df84a0f..001ad83388 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -112,6 +112,8 @@ int32_t mndInitSma(SMnode *pMnode) { void mndCleanupSma(SMnode *pMnode) {} static SSdbRaw *mndSmaActionEncode(SSmaObj *pSma) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; int32_t size = @@ -173,6 +175,8 @@ _OVER: } static SSdbRow *mndSmaActionDecode(SSdbRaw *pRaw) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRow *pRow = NULL; SSmaObj *pSma = NULL; diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index 4243ccb77c..3f65e1c58b 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -79,6 +79,8 @@ void mndReleaseSnode(SMnode *pMnode, SSnodeObj *pObj) { } static SSdbRaw *mndSnodeActionEncode(SSnodeObj *pObj) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRaw *pRaw = sdbAllocRaw(SDB_SNODE, SNODE_VER_NUMBER, sizeof(SSnodeObj) + SNODE_RESERVE_SIZE); @@ -104,6 +106,8 @@ _OVER: } static SSdbRow *mndSnodeActionDecode(SSdbRaw *pRaw) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRow *pRow = NULL; SSnodeObj *pObj = NULL; diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 3fac879ca9..c5e6f38238 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -115,6 +115,8 @@ int32_t mndInitStb(SMnode *pMnode) { void mndCleanupStb(SMnode *pMnode) {} SSdbRaw *mndStbActionEncode(SStbObj *pStb) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; int32_t size = sizeof(SStbObj) + (pStb->numOfColumns + pStb->numOfTags) * sizeof(SSchema) + pStb->commentLen + @@ -205,6 +207,8 @@ _OVER: } static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRow *pRow = NULL; SStbObj *pStb = NULL; diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index d57dc6e52e..32a76afa5b 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -160,6 +160,8 @@ void mndCleanupStream(SMnode *pMnode) { } SSdbRow *mndStreamActionDecode(SSdbRaw *pRaw) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRow *pRow = NULL; diff --git a/source/dnode/mnode/impl/src/mndStreamTrans.c b/source/dnode/mnode/impl/src/mndStreamTrans.c index f252791618..b39487b79f 100644 --- a/source/dnode/mnode/impl/src/mndStreamTrans.c +++ b/source/dnode/mnode/impl/src/mndStreamTrans.c @@ -177,6 +177,8 @@ STrans *doCreateTrans(SMnode *pMnode, SStreamObj *pStream, SRpcMsg *pReq, ETrnCo } SSdbRaw *mndStreamActionEncode(SStreamObj *pStream) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; void *buf = NULL; diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c index e2bedc258a..43e291dc6b 100644 --- a/source/dnode/mnode/impl/src/mndSubscribe.c +++ b/source/dnode/mnode/impl/src/mndSubscribe.c @@ -1096,6 +1096,8 @@ end: void mndCleanupSubscribe(SMnode *pMnode) {} static SSdbRaw *mndSubActionEncode(SMqSubscribeObj *pSub) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; void *buf = NULL; int32_t tlen = tEncodeSubscribeObj(NULL, pSub); @@ -1132,6 +1134,8 @@ SUB_ENCODE_OVER: } static SSdbRow *mndSubActionDecode(SSdbRaw *pRaw) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRow *pRow = NULL; SMqSubscribeObj *pSub = NULL; diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index bcb38a3902..2c7f83729a 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -76,6 +76,8 @@ const char *mndTopicGetShowName(const char topic[TSDB_TOPIC_FNAME_LEN]) { } SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; void *swBuf = NULL; @@ -163,6 +165,8 @@ TOPIC_ENCODE_OVER: } SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRow *pRow = NULL; SMqTopicObj *pTopic = NULL; diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 58dab20859..49d1a4ca97 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -105,6 +105,8 @@ static int32_t mndTransGetActionsSize(SArray *pArray) { } static int32_t mndTransEncodeAction(SSdbRaw *pRaw, int32_t *offset, SArray *pActions, int32_t actionsNum) { + int32_t code = 0; + int32_t lino = 0; int32_t dataPos = *offset; int8_t unused = 0; int32_t ret = -1; @@ -142,6 +144,8 @@ _OVER: } SSdbRaw *mndTransEncode(STrans *pTrans) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_INVALID_MSG; int8_t sver = taosArrayGetSize(pTrans->prepareActions) ? TRANS_VER2_NUMBER : TRANS_VER1_NUMBER; @@ -225,6 +229,8 @@ _OVER: } static int32_t mndTransDecodeAction(SSdbRaw *pRaw, int32_t *offset, SArray *pActions, int32_t actionNum) { + int32_t code = 0; + int32_t lino = 0; STransAction action = {0}; int32_t dataPos = *offset; int8_t unused = 0; @@ -279,7 +285,8 @@ _OVER: SSdbRow *mndTransDecode(SSdbRaw *pRaw) { terrno = TSDB_CODE_INVALID_MSG; - + int32_t code = 0; + int32_t lino = 0; SSdbRow *pRow = NULL; STrans *pTrans = NULL; char *pData = NULL; diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index bae617013c..32b82633fe 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -784,11 +784,11 @@ static int32_t createIpWhiteList(void *buf, int32_t len, SIpWhiteList **ppList) SDecoder decoder = {0}; tDecoderInit(&decoder, buf, len); - TAOS_CHECK_GOTO(tStartDecode(&decoder), &lino, _OVER), &lino, _OVER); - TAOS_CHECK_GOTO(tDecodeI32(&decoder, &num), &lino, _OVER), &lino, _OVER); + TAOS_CHECK_GOTO(tStartDecode(&decoder), &lino, _OVER); + TAOS_CHECK_GOTO(tDecodeI32(&decoder, &num), &lino, _OVER); p = taosMemoryCalloc(1, sizeof(SIpWhiteList) + num * sizeof(SIpV4Range)); - if(p == NULL) { + if (p == NULL) { TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); } TAOS_CHECK_GOTO(tDerializeIpWhileList(buf, len, p), &lino, _OVER); @@ -796,7 +796,12 @@ static int32_t createIpWhiteList(void *buf, int32_t len, SIpWhiteList **ppList) _OVER: tEndDecode(&decoder); tDecoderClear(&decoder); - return p; + if (code != 0) { + taosMemoryFreeClear(p); + mError("failed to create ip white list at line %d since %s", lino, tstrerror(code)); + } + *ppList = p; + TAOS_RETURN(code); } static int32_t createDefaultIpWhiteList(SIpWhiteList **ppWhiteList) { @@ -876,7 +881,8 @@ static int32_t mndCreateDefaultUsers(SMnode *pMnode) { } SSdbRaw *mndUserActionEncode(SUserObj *pUser) { - int32_t code = TSDB_CODE_OUT_OF_MEMORY; + int32_t code = 0; + int32_t lino = 0; int32_t ipWhiteReserve = pUser->pIpWhiteList ? (sizeof(SIpV4Range) * pUser->pIpWhiteList->num + sizeof(SIpWhiteList) + 4) : 16; @@ -989,7 +995,7 @@ SSdbRaw *mndUserActionEncode(SUserObj *pUser) { SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, USER_VER_NUMBER, size); if (pRaw == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER); + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); } int32_t dataPos = 0; @@ -1744,21 +1750,30 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, SCreateUserReq *pCreate if(pUniqueTab == NULL){ TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); } - int32_t dummpy = 0; + int32_t dummpy = 0; for (int i = 0; i < pCreate->numIpRanges; i++) { SIpV4Range range = {.ip = pCreate->pIpRanges[i].ip, .mask = pCreate->pIpRanges[i].mask}; - if(code = taosHashPut(pUniqueTab, &range, sizeof(range), &dummpy, sizeof(dummpy)); + if ((code = taosHashPut(pUniqueTab, &range, sizeof(range), &dummpy, sizeof(dummpy))) != 0) { + taosHashCleanup(pUniqueTab); + TAOS_RETURN(code); + } + } + if ((code = taosHashPut(pUniqueTab, &defaultIpRange, sizeof(defaultIpRange), &dummpy, sizeof(dummpy))) != 0) { + taosHashCleanup(pUniqueTab); + TAOS_RETURN(code); } - taosHashPut(pUniqueTab, &defaultIpRange, sizeof(defaultIpRange), &dummpy, sizeof(dummpy)); if (taosHashGetSize(pUniqueTab) > MND_MAX_USE_HOST) { - terrno = TSDB_CODE_MND_TOO_MANY_USER_HOST; taosHashCleanup(pUniqueTab); - return terrno; + TAOS_RETURN(TSDB_CODE_MND_TOO_MANY_USER_HOST); } int32_t numOfRanges = taosHashGetSize(pUniqueTab); SIpWhiteList *p = taosMemoryCalloc(1, sizeof(SIpWhiteList) + numOfRanges * sizeof(SIpV4Range)); + if (p == NULL) { + taosHashCleanup(pUniqueTab); + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } void *pIter = taosHashIterate(pUniqueTab, NULL); int32_t i = 0; while (pIter) { @@ -1781,9 +1796,8 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, SCreateUserReq *pCreate STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "create-user"); if (pTrans == NULL) { mError("user:%s, failed to create since %s", pCreate->user, terrstr()); - taosMemoryFree(userObj.pIpWhiteList); - return -1; + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); } mInfo("trans:%d, used to create user:%s", pTrans->id, pCreate->user); diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 0422bfabff..160d16667f 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -89,6 +89,8 @@ int32_t mndInitVgroup(SMnode *pMnode) { void mndCleanupVgroup(SMnode *pMnode) {} SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRaw *pRaw = sdbAllocRaw(SDB_VGROUP, VGROUP_VER_NUMBER, sizeof(SVgObj) + VGROUP_RESERVE_SIZE); @@ -127,6 +129,8 @@ _OVER: } SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) { + int32_t code = 0; + int32_t lino = 0; terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRow *pRow = NULL; SVgObj *pVgroup = NULL; diff --git a/source/dnode/mnode/sdb/inc/sdb.h b/source/dnode/mnode/sdb/inc/sdb.h index fc9b89a141..5bb8ae2b5e 100644 --- a/source/dnode/mnode/sdb/inc/sdb.h +++ b/source/dnode/mnode/sdb/inc/sdb.h @@ -39,18 +39,20 @@ extern "C" { #define SDB_GET_VAL(pData, dataPos, val, pos, func, type) \ { \ - if (func(pRaw, dataPos, val) != 0) { \ + if ((code = func(pRaw, dataPos, val)) != 0) { \ + lino = __LINE__; \ goto pos; \ } \ dataPos += sizeof(type); \ } -#define SDB_GET_BINARY(pRaw, dataPos, val, valLen, pos) \ - { \ - if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \ - goto pos; \ - } \ - dataPos += valLen; \ +#define SDB_GET_BINARY(pRaw, dataPos, val, valLen, pos) \ + { \ + if ((code = sdbGetRawBinary(pRaw, dataPos, val, valLen)) != 0) { \ + lino = __LINE__; \ + goto pos; \ + } \ + dataPos += valLen; \ } #define SDB_GET_INT64(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt64, int64_t) @@ -67,7 +69,8 @@ extern "C" { #define SDB_SET_VAL(pRaw, dataPos, val, pos, func, type) \ { \ - if (func(pRaw, dataPos, val) != 0) { \ + if ((code = func(pRaw, dataPos, val)) != 0) { \ + lino = __LINE__; \ goto pos; \ } \ dataPos += sizeof(type); \ @@ -79,12 +82,13 @@ extern "C" { #define SDB_SET_INT8(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt8, int8_t) #define SDB_SET_UINT8(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawUInt8, uint8_t) -#define SDB_SET_BINARY(pRaw, dataPos, val, valLen, pos) \ - { \ - if (sdbSetRawBinary(pRaw, dataPos, val, valLen) != 0) { \ - goto pos; \ - } \ - dataPos += valLen; \ +#define SDB_SET_BINARY(pRaw, dataPos, val, valLen, pos) \ + { \ + if ((code = sdbSetRawBinary(pRaw, dataPos, val, valLen)) != 0) { \ + lino = __LINE__; \ + goto pos; \ + } \ + dataPos += valLen; \ } #define SDB_SET_RESERVE(pRaw, dataPos, valLen, pos) \ @@ -93,11 +97,12 @@ extern "C" { SDB_SET_BINARY(pRaw, dataPos, val, valLen, pos) \ } -#define SDB_SET_DATALEN(pRaw, dataLen, pos) \ - { \ - if (sdbSetRawDataLen(pRaw, dataLen) != 0) { \ - goto pos; \ - } \ +#define SDB_SET_DATALEN(pRaw, dataLen, pos) \ + { \ + if ((code = sdbSetRawDataLen(pRaw, dataLen)) != 0) { \ + lino = __LINE__; \ + goto pos; \ + } \ } typedef struct SMnode SMnode;