X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Ftincd.c;h=35a84be1230e9b74acbb4bd4f8d6ce99ec4622ca;hb=ee03e05ebea39f8d30db87710985c729f7b8bc25;hp=bb928b0dae0c4cd23b28cb487ec2a4d9f79993cf;hpb=f830d756812a2860fe3b758d3fd8605ac338a552;p=tinc diff --git a/src/tincd.c b/src/tincd.c index bb928b0d..35a84be1 100644 --- a/src/tincd.c +++ b/src/tincd.c @@ -48,14 +48,11 @@ #endif #include "conf.h" -#include "control.h" #include "crypto.h" -#include "device.h" #include "event.h" #include "logger.h" #include "names.h" #include "net.h" -#include "netutl.h" #include "process.h" #include "protocol.h" #include "utils.h" @@ -159,6 +156,7 @@ static bool parse_options(int argc, char **argv) { break; case 'c': /* config file */ + free(confbase); confbase = xstrdup(optarg); break; @@ -169,7 +167,7 @@ static bool parse_options(int argc, char **argv) { case 'L': /* no detach */ #ifndef HAVE_MLOCKALL logger(DEBUG_ALWAYS, LOG_ERR, "The %s option is not supported on this platform.", argv[optind - 1]); - return false; + goto exit_fail; #else do_mlock = true; break; @@ -189,6 +187,7 @@ static bool parse_options(int argc, char **argv) { break; case 'n': /* net name given */ + free(netname); netname = xstrdup(optarg); break; @@ -201,7 +200,7 @@ static bool parse_options(int argc, char **argv) { cfg = parse_config_line(optarg, NULL, ++lineno); if(!cfg) { - return false; + goto exit_fail; } list_insert_tail(cmdline_conf, cfg); @@ -212,7 +211,7 @@ static bool parse_options(int argc, char **argv) { case 'R': case 'U': logger(DEBUG_ALWAYS, LOG_ERR, "The %s option is not supported on this platform.", argv[optind - 1]); - return false; + goto exit_fail; #else case 'R': /* chroot to NETNAME dir */ @@ -245,18 +244,20 @@ static bool parse_options(int argc, char **argv) { } if(optarg) { + free(logfilename); logfilename = xstrdup(optarg); } break; case 5: /* open control socket here */ + free(pidfilename); pidfilename = xstrdup(optarg); break; case '?': /* wrong options */ usage(true); - return false; + goto exit_fail; default: break; @@ -266,7 +267,7 @@ static bool parse_options(int argc, char **argv) { if(optind < argc) { fprintf(stderr, "%s: unrecognized argument '%s'\n", argv[0], argv[optind]); usage(true); - return false; + goto exit_fail; } if(!netname && (netname = getenv("NETNAME"))) { @@ -282,7 +283,7 @@ static bool parse_options(int argc, char **argv) { if(netname && !check_netname(netname, false)) { fprintf(stderr, "Invalid character in netname!\n"); - return false; + goto exit_fail; } if(netname && !check_netname(netname, true)) { @@ -290,6 +291,12 @@ static bool parse_options(int argc, char **argv) { } return true; + +exit_fail: + free_names(); + list_delete_list(cmdline_conf); + cmdline_conf = NULL; + return false; } static bool drop_privs(void) { @@ -372,6 +379,15 @@ static BOOL WINAPI console_ctrl_handler(DWORD type) { # define setpriority(level) (setpriority(PRIO_PROCESS, 0, (level))) #endif +static void cleanup() { + if(config_tree) { + exit_configuration(&config_tree); + } + + list_delete_list(cmdline_conf); + free_names(); +} + int main(int argc, char **argv) { program_name = argv[0]; @@ -432,6 +448,8 @@ int main(int argc, char **argv) { } make_names(true); + atexit(cleanup); + chdir(confbase); #ifdef HAVE_MINGW @@ -483,7 +501,7 @@ int main(int argc, char **argv) { srand(now.tv_sec + now.tv_usec); crypto_init(); - if(!read_server_config()) { + if(!read_server_config(config_tree)) { return 1; } @@ -607,9 +625,5 @@ end: crypto_exit(); - exit_configuration(&config_tree); - free(cmdline_conf); - free_names(); - return status; }