From 799df0ceb9d496cb11a60ad130d664836df69823 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 1 Jan 2018 04:28:29 +0100 Subject: [PATCH] server: Free parse result also in afs. Both the server and the afs process need to access the lopsub parse result which is allocated and initialized prior to the fork(2) that creates the afs process. Hence both processes should free this memory on exit. The new public free_lpr() frees the memory allocated by both parse result structures. --- afs.c | 1 + server.c | 19 ++++++++++++++++--- server.h | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/afs.c b/afs.c index d9aa3ce0..ced2e451 100644 --- a/afs.c +++ b/afs.c @@ -1007,6 +1007,7 @@ __noreturn void afs_init(int socket_fd) out_close: close_afs_tables(); out: + free_lpr(); if (ret < 0) PARA_EMERG_LOG("%s\n", para_strerror(-ret)); exit(EXIT_FAILURE); diff --git a/server.c b/server.c index e5335346..076bf4fa 100644 --- a/server.c +++ b/server.c @@ -643,6 +643,21 @@ static int server_select(int max_fileno, fd_set *readfds, fd_set *writefds, return ret; } +/** + * Deallocate all lopsub parse results. + * + * The server allocates a parse result for command line options and optionally + * a second parse result for the effective configuration, defined by merging + * the command line options with the options stored in the configuration file. + * This function frees both structures. + */ +void free_lpr(void) +{ + lls_free_parse_result(server_lpr, CMD_PTR); + if (server_lpr != cmdline_lpr) + lls_free_parse_result(cmdline_lpr, CMD_PTR); +} + /** * The main function of para_server. * @@ -686,8 +701,6 @@ 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); + free_lpr(); exit(ret < 0? EXIT_FAILURE : EXIT_SUCCESS); } diff --git a/server.h b/server.h index 69d27054..d56da7eb 100644 --- a/server.h +++ b/server.h @@ -117,3 +117,4 @@ int handle_connect(int fd); void parse_config_or_die(bool reload); char *server_get_tasks(void); bool process_is_command_handler(void); +void free_lpr(void); -- 2.39.2