From d7a340986ccb34bfb1a4b4bf5b958eb35c4c95cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Thu, 30 Jan 2020 21:51:52 +0100 Subject: [PATCH] Enhance: systemic disposal of struct booth config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Pokorný --- src/config.c | 12 ++++++++++-- src/config.h | 10 ++++++++++ src/main.c | 2 ++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/config.c b/src/config.c index 3b63e2da..0bc7c07f 100644 --- a/src/config.c +++ b/src/config.c @@ -536,7 +536,7 @@ int read_config(struct booth_config **conf_pptr, struct ticket_config *current_tk = NULL; assert(conf_pptr != NULL); - free(*conf_pptr); + config_free(*conf_pptr); fp = fopen(path, "r"); if (!fp) { @@ -899,11 +899,19 @@ int read_config(struct booth_config **conf_pptr, log_error("%s in config file line %d", error, lineno); - free(*conf_pptr); + config_free(*conf_pptr); *conf_pptr = NULL; return -1; } +void config_free(struct booth_config *conf_ptr) +{ + if (conf_ptr != NULL) { + free(conf_ptr->ticket); + } + free(conf_ptr); +} + int check_config(struct booth_config *conf_ptr, int type) { struct passwd *pw; diff --git a/src/config.h b/src/config.h index e9bde826..4132525d 100644 --- a/src/config.h +++ b/src/config.h @@ -345,11 +345,21 @@ struct booth_config { * @param[in] type role currently being acted as * * @return 0 or negative value (-1 or -errno) on error + * + * @note To eventually dispose the associated memory, use #config_free. */ int read_config(struct booth_config **conf_pptr, const booth_transport_table_t *transport, const char *path, int type); +/** + * @internal + * Memory disposal for the config object + * + * @param[inout] conf_ptr config object to free + */ +void config_free(struct booth_config *conf_ptr); + /** * @internal * Check booth configuration diff --git a/src/main.c b/src/main.c index 651ae188..a4047ed1 100644 --- a/src/main.c +++ b/src/main.c @@ -1638,6 +1638,8 @@ int main(int argc, char *argv[], char *envp[]) } out: + config_free(booth_conf); + #ifdef LOGGING_LIBQB qb_log_fini(); #endif