From eed1d76b3f8b08ef060048803690cadcd53f1abe Mon Sep 17 00:00:00 2001 From: hzcheng Date: Tue, 24 Mar 2020 11:01:04 +0800 Subject: [PATCH] TD-34 --- src/vnode/tsdb/src/tsdbCache.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/vnode/tsdb/src/tsdbCache.c b/src/vnode/tsdb/src/tsdbCache.c index f51c7c12d4..3496f6a5c8 100644 --- a/src/vnode/tsdb/src/tsdbCache.c +++ b/src/vnode/tsdb/src/tsdbCache.c @@ -17,8 +17,9 @@ #include "tsdb.h" #include "tsdbCache.h" -static int tsdbAllocBlockFromPool(STsdbCache *pCache); -static void tsdbFreeBlockList(SCacheMem *mem); +static int tsdbAllocBlockFromPool(STsdbCache *pCache); +static void tsdbFreeBlockList(SList *list); +static void tsdbFreeCacheMem(SCacheMem *mem); STsdbCache *tsdbInitCache(int maxBytes, int cacheBlockSize, tsdb_repo_t *pRepo) { STsdbCache *pCache = (STsdbCache *)calloc(1, sizeof(STsdbCache)); @@ -60,8 +61,8 @@ _err: } void tsdbFreeCache(STsdbCache *pCache) { - tsdbFreeBlockList(pCache->imem); - tsdbFreeBlockList(pCache->mem); + tsdbFreeCacheMem(pCache->imem); + tsdbFreeCacheMem(pCache->mem); tsdbFreeBlockList(pCache->pool.memPool); free(pCache); } @@ -90,9 +91,7 @@ void *tsdbAllocFromCache(STsdbCache *pCache, int bytes, TSKEY key) { return ptr; } -static void tsdbFreeBlockList(SCacheMem *mem) { - if (mem == NULL) return; - SList * list = mem->list; +static void tsdbFreeBlockList(SList *list) { SListNode * node = NULL; STsdbCacheBlock *pBlock = NULL; while ((node = tdListPopHead(list)) != NULL) { @@ -101,6 +100,12 @@ static void tsdbFreeBlockList(SCacheMem *mem) { listNodeFree(node); } tdListFree(list); +} + +static void tsdbFreeCacheMem(SCacheMem *mem) { + if (mem == NULL) return; + SList *list = mem->list; + tsdbFreeBlockList(list); free(mem); } -- GitLab