ensure that in all cases the tun fd is closed

This commit is contained in:
Nikos Mavrogiannopoulos
2014-09-21 01:35:50 +02:00
parent 0cd8002f0c
commit a8b32ed8f0
3 changed files with 12 additions and 9 deletions

View File

@@ -128,11 +128,9 @@ int handle_script_exit(main_server_st *s, struct proc_st *proc, int code)
* The parent doesn't need to keep the tunfd, and if it does,
* it causes issues to client.
*/
if (proc->tun_lease.name[0] != 0) {
if (proc->tun_lease.fd >= 0)
close(proc->tun_lease.fd);
proc->tun_lease.fd = -1;
}
if (proc->tun_lease.fd >= 0)
close(proc->tun_lease.fd);
proc->tun_lease.fd = -1;
return ret;
}

View File

@@ -255,7 +255,7 @@ void mslog_hex(const main_server_st * s, const struct proc_st* proc,
int priority, const char *prefix, uint8_t* bin, unsigned bin_size, unsigned b64);
int open_tun(main_server_st* s, struct proc_st* proc);
int close_tun(main_server_st* s, struct proc_st* proc);
void close_tun(main_server_st* s, struct proc_st* proc);
int set_tun_mtu(main_server_st* s, struct proc_st * proc, unsigned mtu);
int send_cookie_auth_reply(main_server_st* s, struct proc_st* proc,

View File

@@ -436,9 +436,9 @@ int open_tun(main_server_st * s, struct proc_st *proc)
return -1;
}
int close_tun(main_server_st * s, struct proc_st *proc)
void close_tun(main_server_st * s, struct proc_st *proc)
{
int fd = -1, ret = 0;
int fd = -1;
#ifdef SIOCIFDESTROY
int e;
@@ -463,5 +463,10 @@ int close_tun(main_server_st * s, struct proc_st *proc)
if (fd != -1)
close(fd);
return ret;
if (proc->tun_lease.fd >= 0) {
close(proc->tun_lease.fd);
proc->tun_lease.fd = -1;
}
return;
}