Ensure config is properly unloaded.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 4 Oct 2008 07:36:42 +0000 (09:36 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 4 Oct 2008 07:36:42 +0000 (09:36 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
postlicyd/config.c
postlicyd/main-postlicyd.c

index d1e4d83..d4131f1 100644 (file)
@@ -77,9 +77,13 @@ config_param_register("verify_filter");
  */
 config_param_register("port");
 
+
+static config_t *global_config = NULL;
+
 static inline config_t *config_new(void)
 {
     config_t *config = p_new(config_t, 1);
+    global_config = config;
     return config;
 }
 
@@ -97,9 +101,17 @@ void config_delete(config_t **config)
     if (*config) {
         config_close(*config);
         p_delete(config);
+        global_config = NULL;
     }
 }
 
+static void config_exit()
+{
+    if (global_config) {
+        config_delete(&global_config);
+    }
+}
+module_exit(config_exit);
 
 static bool config_second_pass(config_t *config)
 {
index 07fe1de..1f286eb 100644 (file)
@@ -219,12 +219,9 @@ int main(int argc, char *argv[])
 
     if (common_setup(pidfile, true, NULL, NULL, daemonize) != EXIT_SUCCESS
         || start_listener(config->port) < 0) {
-        config_delete(&config);
         return EXIT_FAILURE;
     } else {
-        int res = server_loop(query_starter, (delete_client_t)query_delete,
-                              policy_run, config_refresh, config);
-        config_delete(&config);
-        return res;
+        return server_loop(query_starter, (delete_client_t)query_delete,
+                           policy_run, config_refresh, config);
     }
 }