Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/TD-32145-memalloc-check #27949

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions include/libs/monitorfw/taos_monitor_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
#include "taos_metric.h"
#include "tjson.h"

void taos_monitor_split_str(char** arr, char* str, const char* del);
void taos_monitor_split_str_metric(char** arr, taos_metric_t* metric, const char* del, char** buf);
void taos_monitor_split_str(char** arr, char* str, const char* del);
char* taos_monitor_get_metric_name(taos_metric_t* metric);

#endif // TAOS_MONITOR_UTIL_H
22 changes: 22 additions & 0 deletions source/dnode/mnode/impl/src/mndDb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,10 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbCacheInfo *pDbs, int32_t numOfDbs,
}

rsp.useDbRsp = taosMemoryCalloc(1, sizeof(SUseDbRsp));
if (rsp.useDbRsp == NULL) {
mError("db:%s, failed to malloc usedb response", pDbCacheInfo->dbFName);
continue;
}
(void)memcpy(rsp.useDbRsp->db, pDbCacheInfo->dbFName, TSDB_DB_FNAME_LEN);
rsp.useDbRsp->pVgroupInfos = taosArrayInit(10, sizeof(SVgroupInfo));

Expand All @@ -1871,6 +1875,10 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbCacheInfo *pDbs, int32_t numOfDbs,
if (pDb == NULL) {
mTrace("db:%s, no exist", pDbCacheInfo->dbFName);
rsp.useDbRsp = taosMemoryCalloc(1, sizeof(SUseDbRsp));
if (rsp.useDbRsp == NULL) {
mError("db:%s, failed to malloc usedb response", pDbCacheInfo->dbFName);
continue;
}
(void)memcpy(rsp.useDbRsp->db, pDbCacheInfo->dbFName, TSDB_DB_FNAME_LEN);
rsp.useDbRsp->uid = pDbCacheInfo->dbId;
rsp.useDbRsp->vgVersion = -1;
Expand Down Expand Up @@ -1906,6 +1914,11 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbCacheInfo *pDbs, int32_t numOfDbs,

if (pDbCacheInfo->tsmaVersion != pDb->tsmaVersion) {
rsp.pTsmaRsp = taosMemoryCalloc(1, sizeof(STableTSMAInfoRsp));
if (rsp.pTsmaRsp == NULL) {
mndReleaseDb(pMnode, pDb);
mError("db:%s, failed to malloc tsma response", pDb->name);
continue;
}
if (rsp.pTsmaRsp) rsp.pTsmaRsp->pTsmas = taosArrayInit(4, POINTER_BYTES);
if (rsp.pTsmaRsp && rsp.pTsmaRsp->pTsmas) {
bool exist = false;
Expand All @@ -1929,6 +1942,11 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbCacheInfo *pDbs, int32_t numOfDbs,
if (pDbCacheInfo->vgVersion < pDb->vgVersion || numOfTable != pDbCacheInfo->numOfTable ||
pDbCacheInfo->stateTs != pDb->stateTs) {
rsp.useDbRsp = taosMemoryCalloc(1, sizeof(SUseDbRsp));
if (rsp.useDbRsp == NULL) {
mndReleaseDb(pMnode, pDb);
mError("db:%s, failed to malloc usedb response", pDb->name);
continue;
}
rsp.useDbRsp->pVgroupInfos = taosArrayInit(pDb->cfg.numOfVgroups, sizeof(SVgroupInfo));
if (rsp.useDbRsp->pVgroupInfos == NULL) {
mndReleaseDb(pMnode, pDb);
Expand Down Expand Up @@ -2153,6 +2171,9 @@ static char *buildRetension(SArray *pRetension) {
}

char *p1 = taosMemoryCalloc(1, 100);
if (p1 == NULL) {
return NULL;
}
SRetention *p = taosArrayGet(pRetension, 0);

int32_t len = 2;
Expand Down Expand Up @@ -2243,6 +2264,7 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb,
int32_t cols = 0;
int32_t bytes = pShow->pMeta->pSchemas[cols].bytes;
char *buf = taosMemoryMalloc(bytes);
if (buf == NULL) return;

const char *name = mndGetDbStr(pDb->name);
if (name != NULL) {
Expand Down
15 changes: 15 additions & 0 deletions source/dnode/mnode/impl/src/mndDef.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ int32_t tNewSMqConsumerObj(int64_t consumerId, char *cgroup, int8_t updateType,
}

char* topicTmp = taosStrdup(topic);
if (topicTmp == NULL) {
code = terrno;
goto END;
}
if (taosArrayPush(pConsumer->rebNewTopics, &topicTmp) == NULL) {
code = terrno;
goto END;
Expand All @@ -313,6 +317,10 @@ int32_t tNewSMqConsumerObj(int64_t consumerId, char *cgroup, int8_t updateType,
goto END;
}
char* topicTmp = taosStrdup(topic);
if (topicTmp == NULL) {
code = terrno;
goto END;
}
if (taosArrayPush(pConsumer->rebRemovedTopics, &topicTmp) == NULL) {
code = terrno;
goto END;
Expand Down Expand Up @@ -644,6 +652,10 @@ int32_t tCloneSubscribeObj(const SMqSubscribeObj *pSub, SMqSubscribeObj **ppSub)
pSubNew->offsetRows = taosArrayDup(pSub->offsetRows, NULL);
(void)memcpy(pSubNew->dbName, pSub->dbName, TSDB_DB_FNAME_LEN);
pSubNew->qmsg = taosStrdup(pSub->qmsg);
if (pSubNew->qmsg == NULL) {
code = terrno;
goto END;
}
if (ppSub) {
*ppSub = pSubNew;
}
Expand Down Expand Up @@ -726,6 +738,9 @@ void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub, int8_t sver) {
buf = taosDecodeString(buf, &pSub->qmsg);
} else {
pSub->qmsg = taosStrdup("");
if (pSub->qmsg == NULL) {
return NULL;
}
}
return (void *)buf;
}
Expand Down
10 changes: 10 additions & 0 deletions source/dnode/mnode/impl/src/mndDnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,11 @@ static int32_t mndRetrieveDnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pDnode->rebootTime, false);

char *b = taosMemoryCalloc(VARSTR_HEADER_SIZE + strlen(offlineReason[pDnode->offlineReason]) + 1, 1);
if (b == NULL) {
mError("failed to malloc memory for offline reason");
sdbRelease(pSdb, pDnode);
continue;
}
STR_TO_VARSTR(b, online ? "" : offlineReason[pDnode->offlineReason]);

pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
Expand Down Expand Up @@ -1871,6 +1876,11 @@ SArray *mndGetAllDnodeFqdns(SMnode *pMnode) {
if (pIter == NULL) break;

char *fqdn = taosStrdup(pObj->fqdn);
if (fqdn == NULL) {
mError("failed to strdup fqdn, but continue at this time");
sdbRelease(pSdb, pObj);
continue;
}
if (taosArrayPush(fqdns, &fqdn) == NULL) {
mError("failed to fqdn into array, but continue at this time");
}
Expand Down
21 changes: 20 additions & 1 deletion source/dnode/mnode/impl/src/mndFunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ static int32_t mndFuncActionUpdate(SSdb *pSdb, SFuncObj *pOld, SFuncObj *pNew) {
if (pNew->commentSize > 0 && pNew->pComment != NULL) {
pOld->commentSize = pNew->commentSize;
pOld->pComment = taosMemoryMalloc(pOld->commentSize);
if (pOld->pComment == NULL) {
taosWUnLockLatch(&pOld->lock);
return terrno;
}
(void)memcpy(pOld->pComment, pNew->pComment, pOld->commentSize);
}

Expand All @@ -215,6 +219,10 @@ static int32_t mndFuncActionUpdate(SSdb *pSdb, SFuncObj *pOld, SFuncObj *pNew) {
if (pNew->codeSize > 0 && pNew->pCode != NULL) {
pOld->codeSize = pNew->codeSize;
pOld->pCode = taosMemoryMalloc(pOld->codeSize);
if (pOld->pCode == NULL) {
taosWUnLockLatch(&pOld->lock);
return terrno;
}
(void)memcpy(pOld->pCode, pNew->pCode, pOld->codeSize);
}

Expand Down Expand Up @@ -264,7 +272,8 @@ static int32_t mndCreateFunc(SMnode *pMnode, SRpcMsg *pReq, SCreateFuncReq *pCre
}
func.codeSize = pCreate->codeLen;
func.pCode = taosMemoryMalloc(func.codeSize);
if (func.pCode == NULL || func.pCode == NULL) {
if (func.pCode == NULL) {
mError("failed to allocate memory for func code, size:%d", func.codeSize);
code = terrno;
goto _OVER;
}
Expand Down Expand Up @@ -656,6 +665,11 @@ static int32_t mndRetrieveFuncs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl

if (pFunc->pComment) {
char *b2 = taosMemoryCalloc(1, pShow->pMeta->pSchemas[cols].bytes);
if (b2 == NULL) {
mError("failed to allocate memory for comment");
sdbRelease(pSdb, pFunc);
continue;
}
STR_WITH_MAXSIZE_TO_VARSTR(b2, pFunc->pComment, pShow->pMeta->pSchemas[cols].bytes);

pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
Expand Down Expand Up @@ -704,6 +718,11 @@ static int32_t mndRetrieveFuncs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
? TSDB_MAX_BINARY_LEN
: pFunc->codeSize + VARSTR_HEADER_SIZE;
char *b4 = taosMemoryMalloc(varCodeLen);
if (b4 == NULL) {
mError("failed to allocate memory for code");
sdbRelease(pSdb, pFunc);
continue;
}
(void)memcpy(varDataVal(b4), pFunc->pCode, varCodeLen - VARSTR_HEADER_SIZE);
varDataSetLen(b4, varCodeLen - VARSTR_HEADER_SIZE);
(void)colDataSetVal(pColInfo, numOfRows, (const char *)b4, false);
Expand Down
4 changes: 4 additions & 0 deletions source/dnode/mnode/impl/src/mndInfoSchema.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ int32_t mndBuildInsTableCfg(SMnode *pMnode, const char *dbFName, const char *tbN
memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));

pRsp->pSchemaExt = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchemaExt));
if (pRsp->pSchemaExt == NULL) {
code = terrno;
TAOS_RETURN(code);
}
TAOS_RETURN(code);
}

Expand Down
4 changes: 4 additions & 0 deletions source/dnode/mnode/impl/src/mndMnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ static int32_t mndBuildCreateMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *p
int32_t code = 0;
int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pCreateReq);
void *pReq = taosMemoryMalloc(contLen);
if (pReq == NULL) return terrno;
(void)tSerializeSDCreateMnodeReq(pReq, contLen, pCreateReq);

STransAction action = {
Expand All @@ -363,6 +364,7 @@ static int32_t mndBuildAlterMnodeTypeRedoAction(STrans *pTrans, SDAlterMnodeType
int32_t code = 0;
int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pAlterMnodeTypeReq);
void *pReq = taosMemoryMalloc(contLen);
if (pReq == NULL) return terrno;
(void)tSerializeSDCreateMnodeReq(pReq, contLen, pAlterMnodeTypeReq);

STransAction action = {
Expand All @@ -385,6 +387,7 @@ static int32_t mndBuildAlterMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *pA
int32_t code = 0;
int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pAlterReq);
void *pReq = taosMemoryMalloc(contLen);
if (pReq == NULL) return terrno;
(void)tSerializeSDCreateMnodeReq(pReq, contLen, pAlterReq);

STransAction action = {
Expand All @@ -407,6 +410,7 @@ static int32_t mndBuildDropMnodeRedoAction(STrans *pTrans, SDDropMnodeReq *pDrop
int32_t code = 0;
int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, pDropReq);
void *pReq = taosMemoryMalloc(contLen);
if (pReq == NULL) return terrno;
(void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, pDropReq);

STransAction action = {
Expand Down
4 changes: 4 additions & 0 deletions source/dnode/mnode/impl/src/mndScheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,10 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
}
} else {
pSub->qmsg = taosStrdup("");
if (pSub->qmsg == NULL) {
code = terrno;
goto END;
}
}

END:
Expand Down
36 changes: 36 additions & 0 deletions source/dnode/mnode/impl/src/mndStb.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
}

pStb->pCmpr = taosMemoryCalloc(pStb->numOfColumns, sizeof(SColCmpr));
if (pStb->pCmpr == NULL) {
goto _OVER;
}
if (sver < STB_VER_NUMBER) {
// compatible with old data, setup default compress value
// impl later
Expand Down Expand Up @@ -454,6 +457,10 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) {
if (numOfColumns < pNew->numOfColumns) {
taosMemoryFree(pOld->pCmpr);
pOld->pCmpr = taosMemoryCalloc(pNew->numOfColumns, sizeof(SColCmpr));
if (pOld->pCmpr == NULL) {
taosWUnLockLatch(&pOld->lock);
return terrno;
}
memcpy(pOld->pCmpr, pNew->pCmpr, pNew->numOfColumns * sizeof(SColCmpr));
} else {
memcpy(pOld->pCmpr, pNew->pCmpr, pNew->numOfColumns * sizeof(SColCmpr));
Expand Down Expand Up @@ -531,6 +538,9 @@ void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int3
pCmpr->nCols = pStb->numOfColumns;

req.colCmpr.pColCmpr = taosMemoryCalloc(pCmpr->nCols, sizeof(SColCmpr));
if (req.colCmpr.pColCmpr == NULL) {
goto _err;
}
for (int32_t i = 0; i < pStb->numOfColumns; i++) {
SColCmpr *p = &pCmpr->pColCmpr[i];
p->alg = pStb->pCmpr[i].alg;
Expand Down Expand Up @@ -943,6 +953,10 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat
}
// set col compress
pDst->pCmpr = taosMemoryCalloc(1, pDst->numOfColumns * sizeof(SCmprObj));
if (pDst->pCmpr == NULL) {
code = terrno;
TAOS_RETURN(code);
}
for (int32_t i = 0; i < pDst->numOfColumns; i++) {
SFieldWithOptions *pField = taosArrayGet(pCreate->pColumns, i);
SSchema *pSchema = &pDst->pColumns[i];
Expand Down Expand Up @@ -2192,6 +2206,11 @@ static int32_t mndBuildStbCfgImp(SDbObj *pDb, SStbObj *pStb, const char *tbName,
pRsp->commentLen = pStb->commentLen;
if (pStb->commentLen > 0) {
pRsp->pComment = taosStrdup(pStb->comment);
if (pRsp->pComment == NULL) {
taosRUnLockLatch(&pStb->lock);
code = terrno;
TAOS_RETURN(code);
}
}

for (int32_t i = 0; i < pStb->numOfColumns; ++i) {
Expand Down Expand Up @@ -2219,6 +2238,11 @@ static int32_t mndBuildStbCfgImp(SDbObj *pDb, SStbObj *pStb, const char *tbName,
}

pRsp->pSchemaExt = taosMemoryCalloc(pStb->numOfColumns, sizeof(SSchemaExt));
if (pRsp->pSchemaExt == NULL) {
taosRUnLockLatch(&pStb->lock);
code = terrno;
TAOS_RETURN(code);
}
for (int32_t i = 0; i < pStb->numOfColumns; i++) {
SColCmpr *pCmpr = &pStb->pCmpr[i];

Expand Down Expand Up @@ -2352,6 +2376,10 @@ static int32_t mndBuildSMAlterStbRsp(SDbObj *pDb, SStbObj *pObj, void **pCont, i
}

void *cont = taosMemoryMalloc(contLen);
if (cont == NULL) {
tFreeSMAlterStbRsp(&alterRsp);
return terrno;
}
tEncoderInit(&ec, cont, contLen);
code = tEncodeSMAlterStbRsp(&ec, &alterRsp);
tEncoderClear(&ec);
Expand Down Expand Up @@ -2407,6 +2435,10 @@ int32_t mndBuildSMCreateStbRsp(SMnode *pMnode, char *dbFName, char *stbFName, vo
}

void *cont = taosMemoryMalloc(contLen);
if (cont == NULL) {
tFreeSMCreateStbRsp(&stbRsp);
return terrno;
}
tEncoderInit(&ec, cont, contLen);
TAOS_CHECK_GOTO(tEncodeSMCreateStbRsp(&ec, &stbRsp), NULL, _OVER);
tEncoderClear(&ec);
Expand Down Expand Up @@ -4408,6 +4440,10 @@ static int32_t mndDropTbAddTsmaResTbsForSingleVg(SMnode *pMnode, SMndDropTbsWith
taosGetTbHashVal(buf, len, pInfo->dbInfo.hashMethod, pInfo->dbInfo.hashPrefix, pInfo->dbInfo.hashSuffix);
const SVgroupInfo *pVgInfo = taosArraySearch(pInfo->dbInfo.dbVgInfos, &hashVal, vgHashValCmp, TD_EQ);
void *p = taosStrdup(buf + strlen(pInfo->tsmaResTbDbFName) + TSDB_NAME_DELIMITER_LEN);
if (p == NULL) {
code = terrno;
goto _end;
}
if (taosArrayPush(pCtx->pResTbNames, &p) == NULL) {
code = terrno;
goto _end;
Expand Down
3 changes: 3 additions & 0 deletions source/dnode/mnode/impl/src/mndSync.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,9 @@ static int32_t mndApplyQueueItems(const SSyncFSM *pFsm) {

SSyncFSM *mndSyncMakeFsm(SMnode *pMnode) {
SSyncFSM *pFsm = taosMemoryCalloc(1, sizeof(SSyncFSM));
if (pFsm == NULL) {
return NULL;
}
pFsm->data = pMnode;
pFsm->FpCommitCb = mndSyncCommitMsg;
pFsm->FpAppliedIndexCb = mndSyncAppliedIndex;
Expand Down
3 changes: 3 additions & 0 deletions source/dnode/mnode/impl/src/mndTrans.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ SSdbRow *mndTransDecode(SSdbRaw *pRaw) {
SDB_GET_INT32(pRaw, dataPos, &pTrans->paramLen, _OVER)
if (pTrans->paramLen != 0) {
pTrans->param = taosMemoryMalloc(pTrans->paramLen);
if (pTrans->param == NULL) {
goto _OVER;
}
SDB_GET_BINARY(pRaw, dataPos, pTrans->param, pTrans->paramLen, _OVER);
}

Expand Down
1 change: 1 addition & 0 deletions source/libs/monitorfw/src/taos_metric_formatter_custom.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ int taos_metric_formatter_load_sample_new(taos_metric_formatter_t *self, taos_me
int32_t len = end -start;

char* keyvalues = taosMemoryMalloc(len);
if (keyvalues == NULL) return 1;
memset(keyvalues, 0, len);
memcpy(keyvalues, start + 1, len - 1);

Expand Down
Loading