Fix mem leak.

This commit is contained in:
xiao-77 2025-01-09 10:50:23 +08:00
parent ff1ecebdf2
commit 9eb1239783
2 changed files with 18 additions and 24 deletions

View File

@ -312,28 +312,24 @@ int32_t mndInitWriteCfg(SMnode *pMnode) {
if ((code = mndSetCreateConfigCommitLogs(pTrans, versionObj)) != 0) {
mError("failed to init mnd config version, since %s", tstrerror(code));
tFreeSConfigObj(versionObj);
taosMemoryFree(versionObj);
goto _OVER;
}
tFreeSConfigObj(versionObj);
taosMemoryFree(versionObj);
sz = taosArrayGetSize(taosGetGlobalCfg(tsCfg));
for (int i = 0; i < sz; ++i) {
SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i);
SConfigObj *obj = mndInitConfigObj(item);
if (obj == NULL) {
SConfigObj *pObj = mndInitConfigObj(item);
if (pObj == NULL) {
code = terrno;
goto _OVER;
}
if ((code = mndSetCreateConfigCommitLogs(pTrans, obj)) != 0) {
if ((code = mndSetCreateConfigCommitLogs(pTrans, pObj)) != 0) {
mError("failed to init mnd config:%s, since %s", item->name, tstrerror(code));
tFreeSConfigObj(obj);
taosMemoryFree(obj);
tFreeSConfigObj(pObj);
goto _OVER;
}
tFreeSConfigObj(obj);
taosMemoryFree(obj);
tFreeSConfigObj(pObj);
}
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
@ -372,11 +368,11 @@ static int32_t mndTryRebuildConfigSdb(SRpcMsg *pReq) {
if (!mndIsLeader(pMnode)) {
return TSDB_CODE_SUCCESS;
}
int32_t code = 0;
int32_t sz = -1;
STrans *pTrans = NULL;
SAcctObj *vObj = NULL, *obj = NULL;
SArray *addArray = NULL;
int32_t code = 0;
int32_t sz = -1;
STrans *pTrans = NULL;
SConfigObj *vObj = NULL;
SArray *addArray = NULL;
vObj = sdbAcquire(pMnode->pSdb, SDB_CFG, "tsmmConfigVersion");
if (vObj == NULL) {
@ -387,8 +383,9 @@ static int32_t mndTryRebuildConfigSdb(SRpcMsg *pReq) {
addArray = taosArrayInit(4, sizeof(SConfigObj));
for (int i = 0; i < sz; ++i) {
SConfigItem *item = taosArrayGet(taosGetGlobalCfg(tsCfg), i);
obj = sdbAcquire(pMnode->pSdb, SDB_CFG, item->name);
SConfigObj *obj = sdbAcquire(pMnode->pSdb, SDB_CFG, item->name);
if (obj == NULL) {
mInfo("config:%s, not exist in sdb, try to add it", item->name);
SConfigObj *newObj = mndInitConfigObj(item);
if (newObj == NULL) {
code = terrno;
@ -422,7 +419,6 @@ _exit:
mError("failed to try rebuild config in sdb, since %s", tstrerror(code));
}
sdbRelease(pMnode->pSdb, vObj);
sdbRelease(pMnode->pSdb, obj);
cfgObjArrayCleanUp(addArray);
mndTransDrop(pTrans);
TAOS_RETURN(code);

View File

@ -731,10 +731,9 @@ void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub, int8_t sver) {
}
SConfigObj *mndInitConfigObj(SConfigItem *pItem) {
SConfigObj *pObj = taosMemoryCalloc(1, sizeof(SConfigObj));
if (pObj == NULL) {
return NULL;
}
SConfigObj *pObj;
memset(pObj, 0, sizeof(SConfigObj));
tstrncpy(pObj->name, pItem->name, CFG_NAME_MAX_LEN);
pObj->dtype = pItem->dtype;
switch (pItem->dtype) {
@ -823,10 +822,9 @@ int32_t mndUpdateObj(SConfigObj *pObjNew, const char *name, char *value) {
}
SConfigObj *mndInitConfigVersion() {
SConfigObj *pObj = taosMemoryCalloc(1, sizeof(SConfigObj));
if (pObj == NULL) {
return NULL;
}
SConfigObj *pObj;
memset(pObj, 0, sizeof(SConfigObj));
tstrncpy(pObj->name, "tsmmConfigVersion", CFG_NAME_MAX_LEN);
pObj->dtype = CFG_DTYPE_INT32;
pObj->i32 = 0;