]> git.meshlink.io Git - meshlink/commitdiff
Move free()s at the end om main() to the proper destructor functions.
authorGuus Sliepen <guus@tinc-vpn.org>
Fri, 9 Jan 2009 11:36:06 +0000 (12:36 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Fri, 9 Jan 2009 11:36:06 +0000 (12:36 +0100)
src/bsd/device.c
src/cygwin/device.c
src/linux/device.c
src/mingw/device.c
src/net_setup.c
src/raw_socket/device.c
src/solaris/device.c
src/tincd.c
src/uml_socket/device.c

index 01b7071a00687ed1b77b383f1af64ec9d82104a3..d79d52758a8cb178e20243e7940d467b2f0d3283 100644 (file)
@@ -140,6 +140,9 @@ void close_device(void) {
        cp();
 
        close(device_fd);
+
+       free(device);
+       free(iface);
 }
 
 bool read_packet(vpn_packet_t *packet) {
index acb0cfaeb5d4c9199be430d48dc372642e5a33bd..c23d02d7de827aa26f4c59660f3a506f57e249a2 100644 (file)
@@ -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)
index 87f72ea28440fc442c540961258e5d9c2d314b48..0069f54c08b27039405d5842e86f1c0300f0b955 100644 (file)
@@ -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)
index 5494796a11ff289d544650ac3ee545d9a6234503..b13cb569a205e93ea51f148708401cc5f8be9226 100644 (file)
@@ -313,6 +313,9 @@ void close_device(void)
        cp();
 
        CloseHandle(device_handle);
+
+       free(device);
+       free(iface);
 }
 
 bool read_packet(vpn_packet_t *packet)
index f4246db25984e6a89ea19e12916bffdfca35e09b..d6d145ae1721b9a5d09dd9f7d44914e258883194 100644 (file)
@@ -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]);
 
index b96f06f4e46a0f61600fa31168f7aa2471d49bd6..9e306b3901b1699f03e4545de8e209a3fa40adab 100644 (file)
@@ -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)
index 04a36a8580d9b64f2d7faf09841586cd9288dae3..118dfaa1931e29b0d4b9adb2f5507eb1232c5963 100644 (file)
@@ -114,6 +114,9 @@ void close_device(void)
        cp();
 
        close(device_fd);
+
+       free(device);
+       free(iface);
 }
 
 bool read_packet(vpn_packet_t *packet)
index 746fff41129ba6c148b9ddd4f8f7b2fbfdcd8212..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"));
 
@@ -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;
 }
index f81c88f63923840fb22b052081334fbd5f3c2c88..92ec6c3353027c3db42e805fab6ac4a40f7a5f8a 100644 (file)
@@ -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)