conf: do not leak the configuration when freeing it
authorFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 16 Nov 2015 13:51:39 +0000 (14:51 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Mon, 16 Nov 2015 14:26:30 +0000 (15:26 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
src/cfgparser/olsrd_conf.c
src/main.c
src/olsr_cfg.h

index 4d1a44b..bffb987 100644 (file)
@@ -223,7 +223,7 @@ bool loadConfig(int *argc, char *argv[]) {
   }
 
   if (!loadedConfig) {
-    olsrd_free_cnf(olsr_cnf);
+    olsrd_free_cnf(&olsr_cnf);
     olsr_cnf = olsrd_get_default_cnf(strdup(conf_file_name));
   }
 
@@ -985,8 +985,16 @@ olsrd_sanity_check_cnf(struct olsrd_config *cnf)
 }
 
 void
-olsrd_free_cnf(struct olsrd_config *cnf)
+olsrd_free_cnf(struct olsrd_config **cnfVariableAddress)
 {
+  struct olsrd_config *cnf;
+
+  if (!cnfVariableAddress || !*cnfVariableAddress) {
+    return;
+  }
+
+  cnf = *cnfVariableAddress;
+
   free(cnf->smart_gw_status_file);
   cnf->smart_gw_status_file = NULL;
 
@@ -1046,6 +1054,9 @@ olsrd_free_cnf(struct olsrd_config *cnf)
   free(cnf->configuration_file);
   cnf->configuration_file = NULL;
 
+  free(cnf);
+  *cnfVariableAddress = NULL;
+
   return;
 }
 
index a2198da..bf9826d 100644 (file)
@@ -290,7 +290,7 @@ static void olsr_shutdown(int signo __attribute__ ((unused)))
   OLSR_PRINTF(1, "\n <<<< %s - terminating >>>>\n           http://www.olsr.org\n", olsrd_version);
 
   exit_value = olsr_cnf->exit_value;
-  olsrd_free_cnf(olsr_cnf);
+  olsrd_free_cnf(&olsr_cnf);
 
   /* close the log */
   olsr_closelog();
index d04342c..497e477 100644 (file)
@@ -424,7 +424,7 @@ extern "C" {
 
   int olsrd_sanity_check_cnf(struct olsrd_config *);
 
-  void olsrd_free_cnf(struct olsrd_config *);
+  void olsrd_free_cnf(struct olsrd_config **);
 
   void olsrd_print_cnf(struct olsrd_config *);