From 2e969db9d32b8fba8a22125fe5b66323b6d1f71e Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Tue, 7 Jun 2016 11:37:37 +0100 Subject: [PATCH] Improve memory clean-up on exit onak + wotsap were failing to free the memory allocated for the config file name if it was passed on the command line, and the config structure cleanups failed to free any configured sock_dir or the actual DB backend config structure. All of this gets cleaned up by normal program exit (which is when we do our clean-up anyway), but fix it anyway. --- onak-conf.c | 8 +++++++- onak.c | 1 + wotsap.c | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/onak-conf.c b/onak-conf.c index 9f75123..038ad55 100644 --- a/onak-conf.c +++ b/onak-conf.c @@ -45,7 +45,7 @@ struct onak_config config = { .logfile = NULL, .use_keyd = false, - .sock_dir = ".", + .sock_dir = NULL, .backends = NULL, .backends_dir = NULL, @@ -266,6 +266,8 @@ void cleanupdbconfig(void *object) free(dbconfig->password); dbconfig->password = NULL; } + + free(dbconfig); } void cleanupconfig(void) { @@ -301,6 +303,10 @@ void cleanupconfig(void) { free(config.backends_dir); config.backends_dir = NULL; } + if (config.sock_dir != NULL) { + free(config.sock_dir); + config.sock_dir = NULL; + } if (config.bin_dir != NULL) { free(config.bin_dir); config.bin_dir = NULL; diff --git a/onak.c b/onak.c index 08bdd39..ef71341 100644 --- a/onak.c +++ b/onak.c @@ -444,6 +444,7 @@ int main(int argc, char *argv[]) cleanuplogthing(); cleanupconfig(); + free(configfile); return rc; } diff --git a/wotsap.c b/wotsap.c index ce25b02..ca66f85 100644 --- a/wotsap.c +++ b/wotsap.c @@ -215,4 +215,5 @@ int main(int argc, char *argv[]) } cleanuplogthing(); cleanupconfig(); + free(configfile); } -- 2.39.2