Fix a few memory leaks at exit time.
authorGuus Sliepen <guus@tinc-vpn.org>
Wed, 21 Jul 2021 10:35:09 +0000 (12:35 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Wed, 21 Jul 2021 10:35:09 +0000 (12:35 +0200)
Found by Valgrind.

src/dummy_device.c
src/fd_device.c
src/net_setup.c
src/tincctl.c

index 15f0654..94c71ea 100644 (file)
@@ -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) {
index e879a34..1325ee5 100644 (file)
@@ -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) {
index d789126..1257151 100644 (file)
@@ -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++) {
index de171e6..664b2ea 100644 (file)
@@ -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();