提交 784a86e0 编写于 作者: S Shengliang Guan

TD-10431 fix memory leaks

上级 59d8eda4
......@@ -190,6 +190,7 @@ static void mndCleanupSteps(SMnode *pMnode, int32_t pos) {
}
taosArrayClear(pMnode->pSteps);
taosArrayDestroy(pMnode->pSteps);
pMnode->pSteps = NULL;
}
......@@ -306,10 +307,6 @@ void mndClose(SMnode *pMnode) {
if (pMnode != NULL) {
mDebug("start to close mnode");
mndCleanupSteps(pMnode, -1);
if (pMnode->pSteps != NULL) {
taosArrayDestroy(pMnode->pSteps);
pMnode->pSteps = NULL;
}
tfree(pMnode->path);
tfree(pMnode->charset);
tfree(pMnode->locale);
......
......@@ -74,7 +74,7 @@ void sdbCleanup(SSdb *pSdb) {
if (hash == NULL) continue;
SdbDeleteFp deleteFp = pSdb->deleteFps[i];
SSdbRow **ppRow = taosHashIterate(hash, ppRow);
SSdbRow **ppRow = taosHashIterate(hash, NULL);
while (ppRow != NULL) {
SSdbRow *pRow = *ppRow;
if (pRow == NULL) continue;
......@@ -94,40 +94,42 @@ void sdbCleanup(SSdb *pSdb) {
taosHashClear(hash);
taosHashCleanup(hash);
pSdb->hashObjs[i] = NULL;
mTrace("sdb table:%d is cleaned up", i);
}
free(pSdb);
mDebug("sdb is cleaned up");
}
int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
ESdbType sdb = table.sdbType;
pSdb->keyTypes[sdb] = table.keyType;
pSdb->insertFps[sdb] = table.insertFp;
pSdb->updateFps[sdb] = table.updateFp;
pSdb->deleteFps[sdb] = table.deleteFp;
pSdb->deployFps[sdb] = table.deployFp;
pSdb->encodeFps[sdb] = table.encodeFp;
pSdb->decodeFps[sdb] = table.decodeFp;
for (ESdbType i = 0; i < SDB_MAX; ++i) {
int32_t type;
if (pSdb->keyTypes[i] == SDB_KEY_INT32) {
type = TSDB_DATA_TYPE_INT;
} else if (pSdb->keyTypes[i] == SDB_KEY_INT64) {
type = TSDB_DATA_TYPE_BIGINT;
} else {
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;
}
ESdbType sdbType = table.sdbType;
EKeyType keyType = table.keyType;
pSdb->keyTypes[sdbType] = table.keyType;
pSdb->insertFps[sdbType] = table.insertFp;
pSdb->updateFps[sdbType] = table.updateFp;
pSdb->deleteFps[sdbType] = table.deleteFp;
pSdb->deployFps[sdbType] = table.deployFp;
pSdb->encodeFps[sdbType] = table.encodeFp;
pSdb->decodeFps[sdbType] = table.decodeFp;
int32_t hashType = 0;
if (keyType == SDB_KEY_INT32) {
hashType = TSDB_DATA_TYPE_INT;
} else if (keyType == SDB_KEY_INT64) {
hashType = TSDB_DATA_TYPE_BIGINT;
} else {
hashType = TSDB_DATA_TYPE_BINARY;
}
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;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册