Move free()s at the end om main() to the proper destructor functions.
[oweals/tinc.git] / src / tincd.c
index b22a8109ea22fcee524c80dc75e6c79163d77c72..c4e8fad3746cd5d11a430a245b41e2a72563a788 100644 (file)
@@ -392,6 +392,14 @@ static void make_names(void)
        }
 }
 
+static void free_names() {
+       if (identname) free(identname);
+       if (netname) free(netname);
+       if (pidfilename) free(pidfilename);
+       if (logfilename) free(logfilename);
+       if (confbase) free(confbase);
+}
+
 int main(int argc, char **argv)
 {
        program_name = argv[0];
@@ -498,11 +506,11 @@ int main2(int argc, char **argv)
 
        /* Shutdown properly. */
 
-       close_network_connections();
-
        ifdebug(CONNECTIONS)
                dump_device_stats();
 
+       close_network_connections();
+
 end:
        logger(LOG_NOTICE, _("Terminating"));
 
@@ -511,6 +519,13 @@ end:
 #endif
 
        EVP_cleanup();
+       ENGINE_cleanup();
+       CRYPTO_cleanup_all_ex_data();
+       ERR_remove_state(0);
+       ERR_free_strings();
+
+       exit_configuration(&config_tree);
+       free_names();
        
        return status;
 }