From fa7b2cc15b62c0e101043dd2a6d12eddeb372cb4 Mon Sep 17 00:00:00 2001 From: liqiang Date: Mon, 21 Aug 2023 21:01:10 +0800 Subject: [PATCH] fix memory leak in qtcfg Signed-off-by: liqiang --- qtfs/qtfs/qtfs-mod.c | 3 ++- qtfs/qtfs/qtfs-mod.h | 1 + qtfs/qtfs_common/misc.c | 6 ++++++ qtfs/qtfs_server/qtfs-server.c | 15 +++++++++++++++ qtfs/qtfs_server/qtfs-server.h | 1 + 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/qtfs/qtfs/qtfs-mod.c b/qtfs/qtfs/qtfs-mod.c index e4fb904..e2648cd 100644 --- a/qtfs/qtfs/qtfs-mod.c +++ b/qtfs/qtfs/qtfs-mod.c @@ -221,6 +221,7 @@ static int __init qtfs_init(void) ret = -ENOMEM; goto cache_create_err; } + qtfs_whitelist_initset(); qtfs_conn_param_init(); g_qtfs_epoll_thread = kthread_run(qtfs_epoll_thread, NULL, "qtfs_epoll"); if (IS_ERR_OR_NULL(g_qtfs_epoll_thread)) { @@ -288,7 +289,7 @@ static void __exit qtfs_exit(void) kfree(qtfs_epoll_var); qtfs_epoll_var = NULL; } - qtfs_whitelist_initset(); + qtfs_whitelist_exit(); kfree(qtfs_diag_info); qtfs_diag_info = NULL; diff --git a/qtfs/qtfs/qtfs-mod.h b/qtfs/qtfs/qtfs-mod.h index bf38bab..3939e0f 100644 --- a/qtfs/qtfs/qtfs-mod.h +++ b/qtfs/qtfs/qtfs-mod.h @@ -184,6 +184,7 @@ struct dentry *qtfs_fs_mount(struct file_system_type *fs_type, void *qtfs_remote_run(struct qtfs_conn_var_s *pvar, unsigned int type, unsigned int len); int qtfs_misc_register(void); void qtfs_misc_destroy(void); +void qtfs_whitelist_exit(void); long qtfs_misc_ioctl(struct file *file, unsigned int cmd, unsigned long arg); int qtfs_missmsg_proc(struct qtfs_conn_var_s *pvar); int qtfs_utils_register(void); diff --git a/qtfs/qtfs_common/misc.c b/qtfs/qtfs_common/misc.c index beff5cb..6f84b95 100644 --- a/qtfs/qtfs_common/misc.c +++ b/qtfs/qtfs_common/misc.c @@ -257,6 +257,12 @@ void qtfs_whitelist_clearall(void) return; } +void qtfs_whitelist_exit(void) +{ + qtfs_whitelist_clearall(); + return; +} + long qtfs_misc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { long ret = QTOK; diff --git a/qtfs/qtfs_server/qtfs-server.c b/qtfs/qtfs_server/qtfs-server.c index e691574..12d2ed0 100644 --- a/qtfs/qtfs_server/qtfs-server.c +++ b/qtfs/qtfs_server/qtfs-server.c @@ -46,6 +46,19 @@ struct qtfs_server_epoll_s qtfs_epoll = { }; rwlock_t qtfs_epoll_rwlock; +void qtfs_server_epoll_exit(void) +{ + write_lock(&qtfs_epoll_rwlock); + if (qtfs_epoll.kevents == NULL) { + write_unlock(&qtfs_epoll_rwlock); + return; + } + kfree(qtfs_epoll.kevents); + qtfs_epoll.kevents = NULL; + write_unlock(&qtfs_epoll_rwlock); + return; +} + long qtfs_server_epoll_thread(struct qtfs_conn_var_s *pvar) { int n; @@ -412,6 +425,8 @@ static void __exit qtfs_server_exit(void) qtfs_fd_bitmap.nbits = 0; } write_unlock(&g_userp_rwlock); + qtfs_whitelist_exit(); + qtfs_server_epoll_exit(); qtfs_misc_destroy(); qtfs_syscall_replace_stop(); diff --git a/qtfs/qtfs_server/qtfs-server.h b/qtfs/qtfs_server/qtfs-server.h index bfab00a..8135dbb 100644 --- a/qtfs/qtfs_server/qtfs-server.h +++ b/qtfs/qtfs_server/qtfs-server.h @@ -43,6 +43,7 @@ int qtfs_conn_server_run(struct qtfs_conn_var_s *pvar); long qtfs_misc_ioctl(struct file *file, unsigned int cmd, unsigned long arg); int qtfs_misc_register(void); void qtfs_misc_destroy(void); +void qtfs_whitelist_exit(void); long qtfs_misc_ioctl(struct file *file, unsigned int cmd, unsigned long arg); void qtfs_whitelist_clearall(void); void qtfs_whitelist_initset(void); -- Gitee