From b37185e5403c514d5b80208bc92ae53408c6ccc8 Mon Sep 17 00:00:00 2001 From: hzcheng Date: Thu, 9 Apr 2020 04:30:33 +0000 Subject: [PATCH] fix part of mem-leak --- src/common/src/dataformat.c | 2 +- src/vnode/main/src/vnodeWrite.c | 3 +++ src/vnode/tsdb/src/tsdbFile.c | 1 + src/vnode/tsdb/src/tsdbMain.c | 8 ++++++-- src/vnode/tsdb/src/tsdbMeta.c | 13 ++++++++++++- src/vnode/tsdb/src/tsdbMetaFile.c | 1 + 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/common/src/dataformat.c b/src/common/src/dataformat.c index bff041df1b..45850d1788 100644 --- a/src/common/src/dataformat.c +++ b/src/common/src/dataformat.c @@ -141,7 +141,7 @@ STSchema *tdDupSchema(STSchema *pSchema) { * Free the SSchema object created by tdNewSchema or tdDupSchema */ void tdFreeSchema(STSchema *pSchema) { - if (pSchema == NULL) free(pSchema); + if (pSchema != NULL) free(pSchema); } /** diff --git a/src/vnode/main/src/vnodeWrite.c b/src/vnode/main/src/vnodeWrite.c index c6699bd62c..648e7197b0 100644 --- a/src/vnode/main/src/vnodeWrite.c +++ b/src/vnode/main/src/vnodeWrite.c @@ -25,6 +25,7 @@ #include "dataformat.h" #include "vnode.h" #include "vnodeInt.h" +#include "tutil.h" static int32_t (*vnodeProcessWriteMsgFp[TSDB_MSG_TYPE_MAX])(SVnodeObj *, void *, SRspRet *); static int32_t vnodeProcessSubmitMsg(SVnodeObj *pVnode, void *pMsg, SRspRet *); @@ -157,6 +158,8 @@ static int32_t vnodeProcessCreateTableMsg(SVnodeObj *pVnode, void *pCont, SRspRe void *pTsdb = vnodeGetTsdb(pVnode); code = tsdbCreateTable(pTsdb, &tCfg); + tfree(pDestSchema); + dTrace("pVnode:%p vgId:%d, table:%s is created, result:%x", pVnode, pVnode->vgId, pTable->tableId, code); return code; } diff --git a/src/vnode/tsdb/src/tsdbFile.c b/src/vnode/tsdb/src/tsdbFile.c index bd6699eb84..8bdfe63002 100644 --- a/src/vnode/tsdb/src/tsdbFile.c +++ b/src/vnode/tsdb/src/tsdbFile.c @@ -62,6 +62,7 @@ STsdbFileH *tsdbInitFileH(char *dataDir, int maxFiles) { // TODO } } + closedir(dir); return pFileH; } diff --git a/src/vnode/tsdb/src/tsdbMain.c b/src/vnode/tsdb/src/tsdbMain.c index 61f4995e43..aa185f4bf2 100644 --- a/src/vnode/tsdb/src/tsdbMain.c +++ b/src/vnode/tsdb/src/tsdbMain.c @@ -268,6 +268,9 @@ int32_t tsdbCloseRepo(tsdb_repo_t *repo) { tsdbFreeCache(pRepo->tsdbCache); + tfree(pRepo->rootDir); + tfree(pRepo); + return 0; } @@ -847,6 +850,7 @@ static void *tsdbCommitData(void *arg) { tsdbLockRepo(arg); tdListMove(pCache->imem->list, pCache->pool.memPool); + tdListFree(pCache->imem->list); free(pCache->imem); pCache->imem = NULL; pRepo->commit = 0; @@ -1125,11 +1129,11 @@ static int tsdbWriteBlockToFileImpl(SFile *pFile, SDataCols *pCols, int pointsTo *len += pCompCol->len; } - if (pCompData == NULL) free((void *)pCompData); + tfree(pCompData); return 0; _err: - if (pCompData == NULL) free((void *)pCompData); + tfree(pCompData); return -1; } diff --git a/src/vnode/tsdb/src/tsdbMeta.c b/src/vnode/tsdb/src/tsdbMeta.c index 0c6fc61701..22f7357135 100644 --- a/src/vnode/tsdb/src/tsdbMeta.c +++ b/src/vnode/tsdb/src/tsdbMeta.c @@ -312,6 +312,14 @@ int32_t tsdbDropTableImpl(STsdbMeta *pMeta, STableId tableId) { // return 0; // } +static void tsdbFreeMemTable(SMemTable *pMemTable) { + if (pMemTable) { + tSkipListDestroy(pMemTable->pData); + } + + free(pMemTable); +} + static int tsdbFreeTable(STable *pTable) { // TODO: finish this function if (pTable->type == TSDB_CHILD_TABLE) { @@ -323,7 +331,10 @@ static int tsdbFreeTable(STable *pTable) { // Free content if (TSDB_TABLE_IS_SUPER_TABLE(pTable)) { tSkipListDestroy(pTable->pIndex); - } + } + + tsdbFreeMemTable(pTable->mem); + tsdbFreeMemTable(pTable->imem); free(pTable); return 0; diff --git a/src/vnode/tsdb/src/tsdbMetaFile.c b/src/vnode/tsdb/src/tsdbMetaFile.c index d3cff1772c..6821fc2d98 100644 --- a/src/vnode/tsdb/src/tsdbMetaFile.c +++ b/src/vnode/tsdb/src/tsdbMetaFile.c @@ -177,6 +177,7 @@ void tsdbCloseMetaFile(SMetaFile *mfh) { close(mfh->fd); taosHashCleanup(mfh->map); + tfree(mfh); } static int32_t tsdbGetMetaFileName(char *rootDir, char *fname) { -- GitLab