X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fuml_socket%2Fdevice.c;h=ec9dcb1efa2b7702b1baea71ecf0cb751b0edd39;hb=f1fec466e232c00c668422014029dce9114d3add;hp=669d78edeb2eebb375559a5243123c4c81663868;hpb=f02d3ed3e135b5326003e7f69f8331ff6a3cc219;p=tinc diff --git a/src/uml_socket/device.c b/src/uml_socket/device.c index 669d78ed..ec9dcb1e 100644 --- a/src/uml_socket/device.c +++ b/src/uml_socket/device.c @@ -1,7 +1,7 @@ /* device.c -- UML network socket Copyright (C) 2002-2005 Ivo Timmermans, - 2002-2006 Guus Sliepen + 2002-2009 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -36,9 +36,9 @@ static int request_fd = -1; static int data_fd = -1; static int write_fd = -1; static int state = 0; -char *device; +char *device = NULL; char *iface = NULL; -char *device_info; +static char *device_info; extern char *identname; extern bool running; @@ -70,7 +70,7 @@ bool setup_device(void) { cp(); if(!get_config_string(lookup_config(config_tree, "Device"), &device)) - asprintf(&device, LOCALSTATEDIR "/run/%s.umlsocket", identname); + xasprintf(&device, LOCALSTATEDIR "/run/%s.umlsocket", identname); get_config_string(lookup_config(config_tree, "Interface"), &iface); @@ -169,10 +169,13 @@ void close_device(void) { close(write_fd); unlink(device); + + free(device); + if(iface) free(iface); } bool read_packet(vpn_packet_t *packet) { - int lenin; + int inlen; cp(); @@ -202,7 +205,7 @@ bool read_packet(vpn_packet_t *packet) { } case 1: { - if((lenin = read(request_fd, &request, sizeof request)) != sizeof request) { + if((inlen = read(request_fd, &request, sizeof request)) != sizeof request) { logger(LOG_ERR, _("Error while reading request from %s %s: %s"), device_info, device, strerror(errno)); running = false; @@ -232,14 +235,14 @@ bool read_packet(vpn_packet_t *packet) { } case 2: { - if((lenin = read(data_fd, packet->data, MTU)) <= 0) { + if((inlen = read(data_fd, packet->data, MTU)) <= 0) { logger(LOG_ERR, _("Error while reading from %s %s: %s"), device_info, device, strerror(errno)); running = false; return false; } - packet->len = lenin; + packet->len = inlen; device_total_in += packet->len;