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

TD-10431 fix memory leaks

上级 59d8eda4
...@@ -190,6 +190,7 @@ static void mndCleanupSteps(SMnode *pMnode, int32_t pos) { ...@@ -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) { ...@@ -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);
......
...@@ -74,7 +74,7 @@ void sdbCleanup(SSdb *pSdb) { ...@@ -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) { ...@@ -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 type; int32_t hashType = 0;
if (pSdb->keyTypes[i] == SDB_KEY_INT32) { if (keyType == SDB_KEY_INT32) {
type = TSDB_DATA_TYPE_INT; hashType = TSDB_DATA_TYPE_INT;
} else if (pSdb->keyTypes[i] == SDB_KEY_INT64) { } else if (keyType == SDB_KEY_INT64) {
type = TSDB_DATA_TYPE_BIGINT; hashType = TSDB_DATA_TYPE_BIGINT;
} else { } else {
type = TSDB_DATA_TYPE_BINARY; hashType = 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; SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(hashType), true, HASH_NO_LOCK);
taosInitRWLatch(&pSdb->locks[i]); 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;
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册