From: Guus Sliepen Date: Fri, 9 Jan 2009 11:36:06 +0000 (+0100) Subject: Move free()s at the end om main() to the proper destructor functions. X-Git-Tag: release-1.0.10~94 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=a39a9506cd041a7092a98498b362eaacfd2f33c3;p=tinc Move free()s at the end om main() to the proper destructor functions. --- diff --git a/src/bsd/device.c b/src/bsd/device.c index 01b7071a..d79d5275 100644 --- a/src/bsd/device.c +++ b/src/bsd/device.c @@ -140,6 +140,9 @@ void close_device(void) { cp(); close(device_fd); + + free(device); + free(iface); } bool read_packet(vpn_packet_t *packet) { diff --git a/src/cygwin/device.c b/src/cygwin/device.c index acb0cfae..c23d02d7 100644 --- a/src/cygwin/device.c +++ b/src/cygwin/device.c @@ -227,6 +227,9 @@ void close_device(void) CloseHandle(device_handle); kill(reader_pid, SIGKILL); + + free(device); + free(iface); } bool read_packet(vpn_packet_t *packet) diff --git a/src/linux/device.c b/src/linux/device.c index 87f72ea2..0069f54c 100644 --- a/src/linux/device.c +++ b/src/linux/device.c @@ -44,8 +44,8 @@ typedef enum device_type_t { int device_fd = -1; static device_type_t device_type; -char *device; -char *iface; +char *device = NULL; +char *iface = NULL; static char ifrname[IFNAMSIZ]; static char *device_info; @@ -93,11 +93,13 @@ bool setup_device(void) if(!ioctl(device_fd, TUNSETIFF, &ifr)) { strncpy(ifrname, ifr.ifr_name, IFNAMSIZ); - iface = ifrname; + if(iface) free(iface); + iface = xstrdup(ifrname); } else if(!ioctl(device_fd, (('T' << 8) | 202), &ifr)) { logger(LOG_WARNING, _("Old ioctl() request was needed for %s"), device); strncpy(ifrname, ifr.ifr_name, IFNAMSIZ); - iface = ifrname; + if(iface) free(iface); + iface = xstrdup(ifrname); } else #endif { @@ -105,7 +107,9 @@ bool setup_device(void) overwrite_mac = true; device_info = _("Linux ethertap device"); device_type = DEVICE_TYPE_ETHERTAP; - iface = rindex(device, '/') ? rindex(device, '/') + 1 : device; + if(iface) + free(iface); + iface = xstrdup(rindex(device, '/') ? rindex(device, '/') + 1 : device); } logger(LOG_INFO, _("%s is a %s"), device, device_info); @@ -118,6 +122,9 @@ void close_device(void) cp(); close(device_fd); + + free(device); + free(iface); } bool read_packet(vpn_packet_t *packet) diff --git a/src/mingw/device.c b/src/mingw/device.c index 5494796a..b13cb569 100644 --- a/src/mingw/device.c +++ b/src/mingw/device.c @@ -313,6 +313,9 @@ void close_device(void) cp(); CloseHandle(device_handle); + + free(device); + free(iface); } bool read_packet(vpn_packet_t *packet) diff --git a/src/net_setup.c b/src/net_setup.c index f4246db2..d6d145ae 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -608,6 +608,8 @@ void close_network_connections(void) execute_script("tinc-down", envp); + if(myport) free(myport); + for(i = 0; i < 4; i++) free(envp[i]); diff --git a/src/raw_socket/device.c b/src/raw_socket/device.c index b96f06f4..9e306b39 100644 --- a/src/raw_socket/device.c +++ b/src/raw_socket/device.c @@ -32,8 +32,8 @@ #include "xalloc.h" int device_fd = -1; -char *device; -char *iface; +char *device = NULL; +char *iface = NULL; static char ifrname[IFNAMSIZ]; static char *device_info; @@ -90,6 +90,9 @@ void close_device(void) cp(); close(device_fd); + + free(device); + free(iface); } bool read_packet(vpn_packet_t *packet) diff --git a/src/solaris/device.c b/src/solaris/device.c index 04a36a85..118dfaa1 100644 --- a/src/solaris/device.c +++ b/src/solaris/device.c @@ -114,6 +114,9 @@ void close_device(void) cp(); close(device_fd); + + free(device); + free(iface); } bool read_packet(vpn_packet_t *packet) diff --git a/src/tincd.c b/src/tincd.c index 746fff41..c4e8fad3 100644 --- a/src/tincd.c +++ b/src/tincd.c @@ -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")); @@ -510,20 +518,14 @@ end: remove_pid(pidfilename); #endif - if (identname) free(identname); - if (netname) free(netname); - if (pidfilename) free(pidfilename); - if (logfilename) free(logfilename); - if (myport) free(myport); - if (device) free(device); - if (iface) free(iface); - if (confbase) free(confbase); - EVP_cleanup(); ENGINE_cleanup(); CRYPTO_cleanup_all_ex_data(); ERR_remove_state(0); ERR_free_strings(); + + exit_configuration(&config_tree); + free_names(); return status; } diff --git a/src/uml_socket/device.c b/src/uml_socket/device.c index f81c88f6..92ec6c33 100644 --- a/src/uml_socket/device.c +++ b/src/uml_socket/device.c @@ -171,6 +171,9 @@ void close_device(void) close(write_fd); unlink(device); + + free(device); + if(iface) free(iface); } bool read_packet(vpn_packet_t *packet)