From ac93cb364106bbaa88bf0d0852981a872166e6a9 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 22 Oct 2017 14:46:16 +0200 Subject: [PATCH] server: Deplete user list on exit. This eliminates a bunch of valgrind memory leak warnings when run with --leak-check=full --show-leak-kinds=all. --- server.c | 1 + user_list.c | 27 ++++++++++++++++++++------- user_list.h | 1 + 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/server.c b/server.c index 20019ef6..8b13d35b 100644 --- a/server.c +++ b/server.c @@ -684,6 +684,7 @@ int main(int argc, char *argv[]) } vss_shutdown(); shm_detach(mmd); + user_list_deplete(); lls_free_parse_result(server_lpr, CMD_PTR); if (server_lpr != cmdline_lpr) lls_free_parse_result(cmdline_lpr, CMD_PTR); diff --git a/user_list.c b/user_list.c index a2b49493..18b489b9 100644 --- a/user_list.c +++ b/user_list.c @@ -39,6 +39,24 @@ again: goto again; } +/** + * Remove all entries from the user list. + * + * This is called on shutdown and when the user list is reloaded because the + * server received SIGHUP. + */ +void user_list_deplete(void) +{ + struct user *u, *tmpu; + + list_for_each_entry_safe(u, tmpu, &user_list, node) { + list_del(&u->node); + free(u->name); + free_public_key(u->pubkey); + free(u); + } +} + /** * Initialize the list of users allowed to connect to para_server. * @@ -53,17 +71,12 @@ void user_list_init(char *user_list_file) { int ret = -E_USERLIST; FILE *file_ptr = fopen(user_list_file, "r"); - struct user *u, *tmpu; + struct user *u; if (!file_ptr) goto err; - list_for_each_entry_safe(u, tmpu, &user_list, node) { - list_del(&u->node); - free(u->name); - free_public_key(u->pubkey); - free(u); - } + user_list_deplete(); for (;;) { int num; char line[255]; diff --git a/user_list.h b/user_list.h index 3ef62170..3bc98f68 100644 --- a/user_list.h +++ b/user_list.h @@ -33,4 +33,5 @@ struct user { }; void user_list_init(char *user_list_file); +void user_list_deplete(void); const struct user *user_list_lookup(const char *name); -- 2.39.5