TD-10431 fix memory leaks

This commit is contained in:
Shengliang Guan 2021-12-02 00:02:01 +08:00
parent 59d8eda4c8
commit 784a86e0ad
2 changed files with 30 additions and 31 deletions

View File

@ -190,6 +190,7 @@ static void mndCleanupSteps(SMnode *pMnode, int32_t pos) {
} }
taosArrayClear(pMnode->pSteps); taosArrayClear(pMnode->pSteps);
taosArrayDestroy(pMnode->pSteps);
pMnode->pSteps = NULL; pMnode->pSteps = NULL;
} }
@ -306,10 +307,6 @@ void mndClose(SMnode *pMnode) {
if (pMnode != NULL) { if (pMnode != NULL) {
mDebug("start to close mnode"); mDebug("start to close mnode");
mndCleanupSteps(pMnode, -1); mndCleanupSteps(pMnode, -1);
if (pMnode->pSteps != NULL) {
taosArrayDestroy(pMnode->pSteps);
pMnode->pSteps = NULL;
}
tfree(pMnode->path); tfree(pMnode->path);
tfree(pMnode->charset); tfree(pMnode->charset);
tfree(pMnode->locale); tfree(pMnode->locale);

View File

@ -74,7 +74,7 @@ void sdbCleanup(SSdb *pSdb) {
if (hash == NULL) continue; if (hash == NULL) continue;
SdbDeleteFp deleteFp = pSdb->deleteFps[i]; SdbDeleteFp deleteFp = pSdb->deleteFps[i];
SSdbRow **ppRow = taosHashIterate(hash, ppRow); SSdbRow **ppRow = taosHashIterate(hash, NULL);
while (ppRow != NULL) { while (ppRow != NULL) {
SSdbRow *pRow = *ppRow; SSdbRow *pRow = *ppRow;
if (pRow == NULL) continue; if (pRow == NULL) continue;
@ -94,40 +94,42 @@ void sdbCleanup(SSdb *pSdb) {
taosHashClear(hash); taosHashClear(hash);
taosHashCleanup(hash); taosHashCleanup(hash);
pSdb->hashObjs[i] = NULL; pSdb->hashObjs[i] = NULL;
mTrace("sdb table:%d is cleaned up", i);
} }
free(pSdb);
mDebug("sdb is cleaned up"); mDebug("sdb is cleaned up");
} }
int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) { int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
ESdbType sdb = table.sdbType; ESdbType sdbType = table.sdbType;
pSdb->keyTypes[sdb] = table.keyType; EKeyType keyType = table.keyType;
pSdb->insertFps[sdb] = table.insertFp; pSdb->keyTypes[sdbType] = table.keyType;
pSdb->updateFps[sdb] = table.updateFp; pSdb->insertFps[sdbType] = table.insertFp;
pSdb->deleteFps[sdb] = table.deleteFp; pSdb->updateFps[sdbType] = table.updateFp;
pSdb->deployFps[sdb] = table.deployFp; pSdb->deleteFps[sdbType] = table.deleteFp;
pSdb->encodeFps[sdb] = table.encodeFp; pSdb->deployFps[sdbType] = table.deployFp;
pSdb->decodeFps[sdb] = table.decodeFp; pSdb->encodeFps[sdbType] = table.encodeFp;
pSdb->decodeFps[sdbType] = table.decodeFp;
for (ESdbType i = 0; i < SDB_MAX; ++i) { int32_t hashType = 0;
int32_t type; if (keyType == SDB_KEY_INT32) {
if (pSdb->keyTypes[i] == SDB_KEY_INT32) { hashType = TSDB_DATA_TYPE_INT;
type = TSDB_DATA_TYPE_INT; } else if (keyType == SDB_KEY_INT64) {
} else if (pSdb->keyTypes[i] == SDB_KEY_INT64) { hashType = TSDB_DATA_TYPE_BIGINT;
type = TSDB_DATA_TYPE_BIGINT; } else {
} else { hashType = TSDB_DATA_TYPE_BINARY;
type = TSDB_DATA_TYPE_BINARY;
}
SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(type), true, HASH_NO_LOCK);
if (hash == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
pSdb->hashObjs[i] = hash;
taosInitRWLatch(&pSdb->locks[i]);
} }
SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(hashType), true, HASH_NO_LOCK);
if (hash == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
pSdb->hashObjs[sdbType] = hash;
taosInitRWLatch(&pSdb->locks[sdbType]);
mTrace("sdb table:%d is initialized", sdbType);
return 0; return 0;
} }