Skip to content

Commit

Permalink
cstp: Clean up split include/exclude/DNS lists when freeing vpninfo
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
  • Loading branch information
cernekee committed Jan 15, 2014
1 parent 7265157 commit 58994c2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
41 changes: 23 additions & 18 deletions cstp.c
Expand Up @@ -149,6 +149,28 @@ static void calculate_mtu(struct openconnect_info *vpninfo, int *base_mtu, int *
*mtu = 1280;
}

void cstp_free_splits(struct openconnect_info *vpninfo)
{
struct split_include *inc;

for (inc = vpninfo->split_includes; inc; ) {
struct split_include *next = inc->next;
free(inc);
inc = next;
}
for (inc = vpninfo->split_excludes; inc; ) {
struct split_include *next = inc->next;
free(inc);
inc = next;
}
for (inc = vpninfo->split_dns; inc; ) {
struct split_include *next = inc->next;
free(inc);
inc = next;
}
vpninfo->split_dns = vpninfo->split_includes = vpninfo->split_excludes = NULL;
}

static int start_cstp_connection(struct openconnect_info *vpninfo)
{
char buf[65536];
Expand All @@ -162,7 +184,6 @@ static int start_cstp_connection(struct openconnect_info *vpninfo)
const char *old_netmask = vpninfo->vpn_netmask;
const char *old_addr6 = vpninfo->vpn_addr6;
const char *old_netmask6 = vpninfo->vpn_netmask6;
struct split_include *inc;
int base_mtu, mtu;

/* Clear old options which will be overwritten */
Expand All @@ -174,23 +195,7 @@ static int start_cstp_connection(struct openconnect_info *vpninfo)

for (i = 0; i < 3; i++)
vpninfo->vpn_dns[i] = vpninfo->vpn_nbns[i] = NULL;

for (inc = vpninfo->split_includes; inc; ) {
struct split_include *next = inc->next;
free(inc);
inc = next;
}
for (inc = vpninfo->split_excludes; inc; ) {
struct split_include *next = inc->next;
free(inc);
inc = next;
}
for (inc = vpninfo->split_dns; inc; ) {
struct split_include *next = inc->next;
free(inc);
inc = next;
}
vpninfo->split_dns = vpninfo->split_includes = vpninfo->split_excludes = NULL;
cstp_free_splits(vpninfo);

/* Create (new) random master key for DTLS connection, if needed */
if (vpninfo->dtls_times.last_rekey + vpninfo->dtls_times.rekey <
Expand Down
1 change: 1 addition & 0 deletions library.c
Expand Up @@ -131,6 +131,7 @@ void openconnect_vpninfo_free(struct openconnect_info *vpninfo)
free_optlist(vpninfo->cookies);
free_optlist(vpninfo->cstp_options);
free_optlist(vpninfo->dtls_options);
cstp_free_splits(vpninfo);
free(vpninfo->hostname);
free(vpninfo->urlpath);
free(vpninfo->redirect_url);
Expand Down
1 change: 1 addition & 0 deletions openconnect-internal.h
Expand Up @@ -386,6 +386,7 @@ void dtls_close(struct openconnect_info *vpninfo, int kill_handshake_too);
int cstp_mainloop(struct openconnect_info *vpninfo, int *timeout);
int cstp_bye(struct openconnect_info *vpninfo, const char *reason);
int cstp_reconnect(struct openconnect_info *vpninfo);
void cstp_free_splits(struct openconnect_info *vpninfo);

/* ssl.c */
int connect_https_socket(struct openconnect_info *vpninfo);
Expand Down

0 comments on commit 58994c2

Please sign in to comment.