zlogger: free unused thread hashtable entries 41/283241/1
authorMarek Szyprowski <m.szyprowski@samsung.com>
Thu, 20 Oct 2022 19:57:49 +0000 (21:57 +0200)
committerMarek Szyprowski <m.szyprowski@samsung.com>
Thu, 20 Oct 2022 19:57:49 +0000 (21:57 +0200)
Change-Id: Ifcc729d4a0b8286df5cf2697d93aa5819deb0c5c
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
kernel/zlogger/zlogger.c

index fbc7456be69f76bf1332895cb3433c351be728e4..7652f5be0c30ec8fc5d9e93b5396db6338cfe2e0 100644 (file)
@@ -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 */