From 3c071193d8e65a5ab28f7558496606e5040185e2 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 7 Aug 2023 14:08:28 +0800 Subject: [PATCH] fix: memory leak --- source/dnode/vnode/src/tsdb/tsdbFS2.c | 18 ++++++++++++------ source/dnode/vnode/src/tsdb/tsdbFS2.h | 6 +++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.c b/source/dnode/vnode/src/tsdb/tsdbFS2.c index 6e7595c6ef..581af02bd1 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.c @@ -780,9 +780,12 @@ static int32_t tsdbFSRunBgTask(void *arg) { return 0; } -static int32_t tsdbFSScheduleBgTaskImpl(STFileSystem *fs, EFSBgTaskT type, int32_t (*run)(void *), void (*free)(void *), - void *arg, int64_t *taskid) { +static int32_t tsdbFSScheduleBgTaskImpl(STFileSystem *fs, EFSBgTaskT type, int32_t (*run)(void *), + void (*destroy)(void *), void *arg, int64_t *taskid) { if (fs->stop) { + if (destroy) { + destroy(arg); + } return 0; // TODO: use a better error code } @@ -793,6 +796,9 @@ static int32_t tsdbFSScheduleBgTaskImpl(STFileSystem *fs, EFSBgTaskT type, int32 for (STFSBgTask *task = fs->bgTaskQueue->next; task != fs->bgTaskQueue; task = task->next) { if (task->type == type) { + if (destroy) { + destroy(arg); + } return 0; } } @@ -804,7 +810,7 @@ static int32_t tsdbFSScheduleBgTaskImpl(STFileSystem *fs, EFSBgTaskT type, int32 task->type = type; task->run = run; - task->free = free; + task->destroy = destroy; task->arg = arg; task->scheduleTime = taosGetTimestampMs(); task->taskid = ++fs->taskid; @@ -826,10 +832,10 @@ static int32_t tsdbFSScheduleBgTaskImpl(STFileSystem *fs, EFSBgTaskT type, int32 return 0; } -int32_t tsdbFSScheduleBgTask(STFileSystem *fs, EFSBgTaskT type, int32_t (*run)(void *), void (*free)(void *), void *arg, - int64_t *taskid) { +int32_t tsdbFSScheduleBgTask(STFileSystem *fs, EFSBgTaskT type, int32_t (*run)(void *), void (*destroy)(void *), + void *arg, int64_t *taskid) { taosThreadMutexLock(fs->mutex); - int32_t code = tsdbFSScheduleBgTaskImpl(fs, type, run, free, arg, taskid); + int32_t code = tsdbFSScheduleBgTaskImpl(fs, type, run, destroy, arg, taskid); taosThreadMutexUnlock(fs->mutex); return code; } diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.h b/source/dnode/vnode/src/tsdb/tsdbFS2.h index e814ab2fff..70cb1646e7 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.h +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.h @@ -59,8 +59,8 @@ int32_t tsdbFSEditBegin(STFileSystem *fs, const TFileOpArray *opArray, EFEditT e int32_t tsdbFSEditCommit(STFileSystem *fs); int32_t tsdbFSEditAbort(STFileSystem *fs); // background task -int32_t tsdbFSScheduleBgTask(STFileSystem *fs, EFSBgTaskT type, int32_t (*run)(void *), void (*free)(void *), void *arg, - int64_t *taskid); +int32_t tsdbFSScheduleBgTask(STFileSystem *fs, EFSBgTaskT type, int32_t (*run)(void *), void (*destroy)(void *), + void *arg, int64_t *taskid); int32_t tsdbFSWaitBgTask(STFileSystem *fs, int64_t taskid); int32_t tsdbFSWaitAllBgTask(STFileSystem *fs); int32_t tsdbFSDisableBgTask(STFileSystem *fs); @@ -71,7 +71,7 @@ int32_t tsdbFSGetFSet(STFileSystem *fs, int32_t fid, STFileSet **fset); struct STFSBgTask { EFSBgTaskT type; int32_t (*run)(void *arg); - void (*free)(void *arg); + void (*destroy)(void *arg); void *arg; TdThreadCond done[1]; -- GitLab