From: Guus Sliepen Date: Wed, 21 Jul 2021 10:35:09 +0000 (+0200) Subject: Fix a few memory leaks at exit time. X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=f71ab70351e8d5dfdc91c9808d142cf93d2a5d61;p=tinc Fix a few memory leaks at exit time. Found by Valgrind. --- diff --git a/src/dummy_device.c b/src/dummy_device.c index 15f0654f..94c71ea0 100644 --- a/src/dummy_device.c +++ b/src/dummy_device.c @@ -34,6 +34,10 @@ static bool setup_device(void) { } static void close_device(void) { + free(iface); + iface = NULL; + free(device); + device = NULL; } static bool read_packet(vpn_packet_t *packet) { diff --git a/src/fd_device.c b/src/fd_device.c index e879a341..1325ee5a 100644 --- a/src/fd_device.c +++ b/src/fd_device.c @@ -175,6 +175,10 @@ static bool setup_device(void) { static void close_device(void) { close(device_fd); device_fd = -1; + free(iface); + iface = NULL; + free(device); + device = NULL; } static inline uint16_t get_ip_ethertype(vpn_packet_t *packet) { diff --git a/src/net_setup.c b/src/net_setup.c index d7891261..12571518 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -1330,7 +1330,7 @@ void close_network_connections(void) { if(myself && myself->connection) { subnet_update(myself, NULL, false); - connection_del(myself->connection); + free_connection(myself->connection); } for(int i = 0; i < listen_sockets; i++) { diff --git a/src/tincctl.c b/src/tincctl.c index de171e60..664b2eaa 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -3339,6 +3339,11 @@ static int cmd_shell(int argc, char *argv[]) { return result; } +static void cleanup() { + free(tinc_conf); + free(hosts_dir); + free_names(); +} int main(int argc, char *argv[]) { program_name = argv[0]; @@ -3353,6 +3358,7 @@ int main(int argc, char *argv[]) { make_names(false); xasprintf(&tinc_conf, "%s" SLASH "tinc.conf", confbase); xasprintf(&hosts_dir, "%s" SLASH "hosts", confbase); + atexit(cleanup); if(show_version) { version();