Fix a few memory leaks at exit time.
[tinc] / src / fd_device.c
index cfad5af..1325ee5 100644 (file)
@@ -1,7 +1,7 @@
 /*
     fd_device.c -- Interaction with Android tun fd
     Copyright (C)   2001-2005   Ivo Timmermans,
-                    2001-2016   Guus Sliepen <guus@tinc-vpn.org>
+                    2001-2021   Guus Sliepen <guus@tinc-vpn.org>
                     2009        Grzegorz Dymarek <gregd72002@googlemail.com>
                     2016-2020   Pacien TRAN-GIRARD <pacien@pacien.net>
 
     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
+#include "system.h"
+
 #ifdef HAVE_SYS_UN_H
 #include <sys/un.h>
 
-#include "system.h"
 #include "conf.h"
 #include "device.h"
 #include "ethernet.h"
@@ -115,7 +116,9 @@ end:
 }
 
 static struct unix_socket_addr parse_socket_addr(const char *path) {
-       struct sockaddr_un socket_addr;
+       struct sockaddr_un socket_addr = {
+               .sun_family = AF_UNIX,
+       };
        size_t path_length;
 
        if(strlen(path) >= sizeof(socket_addr.sun_path)) {
@@ -125,7 +128,6 @@ static struct unix_socket_addr parse_socket_addr(const char *path) {
                };
        }
 
-       socket_addr.sun_family = AF_UNIX;
        strncpy(socket_addr.sun_path, path, sizeof(socket_addr.sun_path));
 
        if(path[0] == '@') {
@@ -173,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) {