From 2eb6d8a67ceb4979bc0722bc41e44c34fc260a13 Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Thu, 20 Oct 2022 21:57:49 +0200 Subject: [PATCH] zlogger: free unused thread hashtable entries Change-Id: Ifcc729d4a0b8286df5cf2697d93aa5819deb0c5c Signed-off-by: Marek Szyprowski --- kernel/zlogger/zlogger.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/kernel/zlogger/zlogger.c b/kernel/zlogger/zlogger.c index fbc7456..7652f5b 100644 --- a/kernel/zlogger/zlogger.c +++ b/kernel/zlogger/zlogger.c @@ -170,6 +170,12 @@ static struct thread_table_field *set_thread_table(pid_t tid, bool is_stdout, ui return ptr; } +static void clear_thread_table(struct thread_table_field *ptr) +{ + hash_del(&ptr->next); + kfree(ptr); +} + static inline char *get_shared_memory(int dev_index) { if (dev_index < 0 || dev_index >= ZLOGGER_DEVICE_COUNT) { @@ -377,6 +383,7 @@ static int zlogger_release(struct inode *ignored, struct file *file) { if (file->private_data != NULL) { struct zlog_file *zlog_file_data = (struct zlog_file *)file->private_data; + struct thread_table_field *ptr = get_thread_table(current->pid, true); if (zlog_file_data->buffer != NULL) { kfree(zlog_file_data->buffer); @@ -384,6 +391,12 @@ static int zlogger_release(struct inode *ignored, struct file *file) } kfree(file->private_data); file->private_data = NULL; + + if (ptr) { + mutex_lock(&g_block_mutex); + clear_thread_table(ptr); + mutex_unlock(&g_block_mutex); + } } return 0; } @@ -409,8 +422,12 @@ static void zlogger_vm_close(struct vm_area_struct *vma) { struct thread_table_field *ptr = vma->vm_private_data; - if (ptr) + if (ptr) { ptr->vma = NULL; + mutex_lock(&g_block_mutex); + clear_thread_table(ptr); + mutex_unlock(&g_block_mutex); + } } /* called under mmap semaphore */ -- 2.34.1