Make device close cleaner.
This commit is contained in:
parent
6382608653
commit
ed1d0878af
9 changed files with 56 additions and 37 deletions
|
@ -197,9 +197,11 @@ static void close_device(void) {
|
||||||
default:
|
default:
|
||||||
close(device_fd);
|
close(device_fd);
|
||||||
}
|
}
|
||||||
|
device_fd = -1;
|
||||||
|
|
||||||
free(device);
|
free(device); device = NULL;
|
||||||
free(iface);
|
free(iface); iface = NULL;
|
||||||
|
device_info = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool read_packet(vpn_packet_t *packet) {
|
static bool read_packet(vpn_packet_t *packet) {
|
||||||
|
|
|
@ -215,12 +215,13 @@ static bool setup_device(void) {
|
||||||
static void close_device(void) {
|
static void close_device(void) {
|
||||||
close(sp[0]);
|
close(sp[0]);
|
||||||
close(sp[1]);
|
close(sp[1]);
|
||||||
CloseHandle(device_handle);
|
CloseHandle(device_handle); device_handle = INVALID_HANDLE_VALUE;
|
||||||
|
|
||||||
kill(reader_pid, SIGKILL);
|
kill(reader_pid, SIGKILL);
|
||||||
|
|
||||||
free(device);
|
free(device); device = NULL;
|
||||||
free(iface);
|
free(iface); iface = NULL;
|
||||||
|
device_info = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool read_packet(vpn_packet_t *packet) {
|
static bool read_packet(vpn_packet_t *packet) {
|
||||||
|
|
|
@ -110,10 +110,12 @@ static bool setup_device(void) {
|
||||||
|
|
||||||
static void close_device(void) {
|
static void close_device(void) {
|
||||||
close(device_fd);
|
close(device_fd);
|
||||||
|
device_fd = -1;
|
||||||
|
|
||||||
free(type);
|
free(type); type = NULL;
|
||||||
free(device);
|
free(device); device = NULL;
|
||||||
free(iface);
|
free(iface); iface = NULL;
|
||||||
|
device_info = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool read_packet(vpn_packet_t *packet) {
|
static bool read_packet(vpn_packet_t *packet) {
|
||||||
|
|
|
@ -213,10 +213,11 @@ static bool setup_device(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void close_device(void) {
|
static void close_device(void) {
|
||||||
CloseHandle(device_handle);
|
CloseHandle(device_handle); device_handle = INVALID_HANDLE_VALUE;
|
||||||
|
|
||||||
free(device);
|
free(device); device = NULL;
|
||||||
free(iface);
|
free(iface); iface = NULL;
|
||||||
|
device_info = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool read_packet(vpn_packet_t *packet) {
|
static bool read_packet(vpn_packet_t *packet) {
|
||||||
|
|
|
@ -148,13 +148,15 @@ error:
|
||||||
}
|
}
|
||||||
|
|
||||||
static void close_device(void) {
|
static void close_device(void) {
|
||||||
close(device_fd);
|
close(device_fd); device_fd = -1;
|
||||||
|
|
||||||
free(device);
|
free(device); device = NULL;
|
||||||
free(iface);
|
free(iface); iface = NULL;
|
||||||
|
|
||||||
if(ai)
|
if(ai) {
|
||||||
freeaddrinfo(ai);
|
freeaddrinfo(ai); ai = NULL;
|
||||||
|
}
|
||||||
|
device_info = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool read_packet(vpn_packet_t *packet) {
|
static bool read_packet(vpn_packet_t *packet) {
|
||||||
|
|
|
@ -83,10 +83,11 @@ static bool setup_device(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void close_device(void) {
|
static void close_device(void) {
|
||||||
close(device_fd);
|
close(device_fd); device_fd = -1;
|
||||||
|
|
||||||
free(device);
|
free(device); device = NULL;
|
||||||
free(iface);
|
free(iface); iface = NULL;
|
||||||
|
device_info = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool read_packet(vpn_packet_t *packet) {
|
static bool read_packet(vpn_packet_t *packet) {
|
||||||
|
|
|
@ -287,11 +287,11 @@ static void close_device(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close(ip_fd);
|
close(ip_fd); ip_fd = -1;
|
||||||
close(device_fd);
|
close(device_fd); device_fd = -1;
|
||||||
|
|
||||||
free(device);
|
free(device); device = NULL;
|
||||||
free(iface);
|
free(iface); iface = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool read_packet(vpn_packet_t *packet) {
|
static bool read_packet(vpn_packet_t *packet) {
|
||||||
|
|
|
@ -156,22 +156,29 @@ static bool setup_device(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void close_device(void) {
|
void close_device(void) {
|
||||||
if(listen_fd >= 0)
|
if(listen_fd >= 0) {
|
||||||
close(listen_fd);
|
close(listen_fd); listen_fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
if(request_fd >= 0)
|
if(request_fd >= 0) {
|
||||||
close(request_fd);
|
close(request_fd); request_fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
if(data_fd >= 0)
|
if(data_fd >= 0) {
|
||||||
close(data_fd);
|
close(data_fd); data_fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
if(write_fd >= 0)
|
if(write_fd >= 0) {
|
||||||
close(write_fd);
|
close(write_fd); write_fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
unlink(device);
|
unlink(device);
|
||||||
|
|
||||||
free(device);
|
free(device); device = NULL;
|
||||||
if(iface) free(iface);
|
if(iface) {
|
||||||
|
free(iface); iface = NULL;
|
||||||
|
}
|
||||||
|
device_info = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool read_packet(vpn_packet_t *packet) {
|
static bool read_packet(vpn_packet_t *packet) {
|
||||||
|
|
|
@ -82,15 +82,18 @@ static bool setup_device(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void close_device(void) {
|
static void close_device(void) {
|
||||||
if(conn)
|
if(conn) {
|
||||||
plug.vde_close(conn);
|
plug.vde_close(conn); conn = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if(plug.dl_handle)
|
if(plug.dl_handle)
|
||||||
libvdeplug_dynclose(plug);
|
libvdeplug_dynclose(plug);
|
||||||
|
|
||||||
free(device);
|
free(device); device = NULL;
|
||||||
|
|
||||||
free(iface);
|
free(iface); iface = NULL;
|
||||||
|
|
||||||
|
device_info = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool read_packet(vpn_packet_t *packet) {
|
static bool read_packet(vpn_packet_t *packet) {
|
||||||
|
|
Loading…
Reference in a new issue