提交 3c071193 编写于 作者: H Hongze Cheng

fix: memory leak

上级 7ae36630
...@@ -780,9 +780,12 @@ static int32_t tsdbFSRunBgTask(void *arg) { ...@@ -780,9 +780,12 @@ static int32_t tsdbFSRunBgTask(void *arg) {
return 0; return 0;
} }
static int32_t tsdbFSScheduleBgTaskImpl(STFileSystem *fs, EFSBgTaskT type, int32_t (*run)(void *), void (*free)(void *), static int32_t tsdbFSScheduleBgTaskImpl(STFileSystem *fs, EFSBgTaskT type, int32_t (*run)(void *),
void *arg, int64_t *taskid) { void (*destroy)(void *), void *arg, int64_t *taskid) {
if (fs->stop) { if (fs->stop) {
if (destroy) {
destroy(arg);
}
return 0; // TODO: use a better error code return 0; // TODO: use a better error code
} }
...@@ -793,6 +796,9 @@ static int32_t tsdbFSScheduleBgTaskImpl(STFileSystem *fs, EFSBgTaskT type, int32 ...@@ -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) { for (STFSBgTask *task = fs->bgTaskQueue->next; task != fs->bgTaskQueue; task = task->next) {
if (task->type == type) { if (task->type == type) {
if (destroy) {
destroy(arg);
}
return 0; return 0;
} }
} }
...@@ -804,7 +810,7 @@ static int32_t tsdbFSScheduleBgTaskImpl(STFileSystem *fs, EFSBgTaskT type, int32 ...@@ -804,7 +810,7 @@ static int32_t tsdbFSScheduleBgTaskImpl(STFileSystem *fs, EFSBgTaskT type, int32
task->type = type; task->type = type;
task->run = run; task->run = run;
task->free = free; task->destroy = destroy;
task->arg = arg; task->arg = arg;
task->scheduleTime = taosGetTimestampMs(); task->scheduleTime = taosGetTimestampMs();
task->taskid = ++fs->taskid; task->taskid = ++fs->taskid;
...@@ -826,10 +832,10 @@ static int32_t tsdbFSScheduleBgTaskImpl(STFileSystem *fs, EFSBgTaskT type, int32 ...@@ -826,10 +832,10 @@ static int32_t tsdbFSScheduleBgTaskImpl(STFileSystem *fs, EFSBgTaskT type, int32
return 0; return 0;
} }
int32_t tsdbFSScheduleBgTask(STFileSystem *fs, EFSBgTaskT type, int32_t (*run)(void *), void (*free)(void *), void *arg, int32_t tsdbFSScheduleBgTask(STFileSystem *fs, EFSBgTaskT type, int32_t (*run)(void *), void (*destroy)(void *),
int64_t *taskid) { void *arg, int64_t *taskid) {
taosThreadMutexLock(fs->mutex); 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); taosThreadMutexUnlock(fs->mutex);
return code; return code;
} }
......
...@@ -59,8 +59,8 @@ int32_t tsdbFSEditBegin(STFileSystem *fs, const TFileOpArray *opArray, EFEditT e ...@@ -59,8 +59,8 @@ int32_t tsdbFSEditBegin(STFileSystem *fs, const TFileOpArray *opArray, EFEditT e
int32_t tsdbFSEditCommit(STFileSystem *fs); int32_t tsdbFSEditCommit(STFileSystem *fs);
int32_t tsdbFSEditAbort(STFileSystem *fs); int32_t tsdbFSEditAbort(STFileSystem *fs);
// background task // background task
int32_t tsdbFSScheduleBgTask(STFileSystem *fs, EFSBgTaskT type, int32_t (*run)(void *), void (*free)(void *), void *arg, int32_t tsdbFSScheduleBgTask(STFileSystem *fs, EFSBgTaskT type, int32_t (*run)(void *), void (*destroy)(void *),
int64_t *taskid); void *arg, int64_t *taskid);
int32_t tsdbFSWaitBgTask(STFileSystem *fs, int64_t taskid); int32_t tsdbFSWaitBgTask(STFileSystem *fs, int64_t taskid);
int32_t tsdbFSWaitAllBgTask(STFileSystem *fs); int32_t tsdbFSWaitAllBgTask(STFileSystem *fs);
int32_t tsdbFSDisableBgTask(STFileSystem *fs); int32_t tsdbFSDisableBgTask(STFileSystem *fs);
...@@ -71,7 +71,7 @@ int32_t tsdbFSGetFSet(STFileSystem *fs, int32_t fid, STFileSet **fset); ...@@ -71,7 +71,7 @@ int32_t tsdbFSGetFSet(STFileSystem *fs, int32_t fid, STFileSet **fset);
struct STFSBgTask { struct STFSBgTask {
EFSBgTaskT type; EFSBgTaskT type;
int32_t (*run)(void *arg); int32_t (*run)(void *arg);
void (*free)(void *arg); void (*destroy)(void *arg);
void *arg; void *arg;
TdThreadCond done[1]; TdThreadCond done[1];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册