server: Deplete user list on exit.
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 22 Oct 2017 12:46:16 +0000 (14:46 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Tue, 13 Mar 2018 02:28:56 +0000 (03:28 +0100)
This eliminates a bunch of valgrind memory leak warnings when
run with --leak-check=full --show-leak-kinds=all.

server.c
user_list.c
user_list.h

index 20019ef..8b13d35 100644 (file)
--- 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);
index a2b4949..18b489b 100644 (file)
@@ -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];
index 3ef6217..3bc98f6 100644 (file)
@@ -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);