X-Git-Url: https://git.librecmc.org/?p=oweals%2Ftinc.git;a=blobdiff_plain;f=src%2Flinux%2Fdevice.c;h=0069f54c08b27039405d5842e86f1c0300f0b955;hp=87f72ea28440fc442c540961258e5d9c2d314b48;hb=a39a9506cd041a7092a98498b362eaacfd2f33c3;hpb=67df7fb7e1c9eefe4bbc920fdc68b595ef28abd9 diff --git a/src/linux/device.c b/src/linux/device.c index 87f72ea..0069f54 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)