From 4ec277433d86b73d6739c98ffb24b5535ad83bc0 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Wed, 8 Jan 2020 10:02:25 -0500 Subject: [PATCH] Free memory of all allocated threads. This pach fixes memory leak which appeared due to commit d483951ebe6e040e53579. Signed-off-by: Michal Mielewczyk --- modules/cas_cache/threads.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/cas_cache/threads.c b/modules/cas_cache/threads.c index 3ffcd42..8c610c2 100644 --- a/modules/cas_cache/threads.c +++ b/modules/cas_cache/threads.c @@ -52,8 +52,10 @@ static int _cas_io_queue_thread(void *data) /* If we get here, then thread was signalled to terminate. * So, let's free memory and exit. */ + wait_for_completion(&info->compl); printk(KERN_DEBUG "Thread %s stopped\n", info->name); kfree(info); + do_exit(0); return 0; } @@ -112,7 +114,9 @@ static int _cas_cleaner_thread(void *data) } } while (true); - complete_and_exit(&info->compl, 0); + wait_for_completion(&info->compl); + kfree(info); + do_exit(0); return 0; } @@ -144,7 +148,9 @@ static int _cas_metadata_updater_thread(void *data) atomic_read(&info->kicked)); } while (true); - complete_and_exit(&info->compl, 0); + wait_for_completion(&info->compl); + kfree(info); + do_exit(0); return 0; } @@ -202,8 +208,10 @@ static void _cas_start_thread(struct cas_thread_info *info) static void _cas_stop_thread(struct cas_thread_info *info) { if (info->running && info->thread) { + reinit_completion(&info->compl); atomic_set(&info->stop, 1); wake_up(&info->wq); + complete(&info->compl); } }