[PATCH/RFC V2 16/26] cstp: Clean up split include/exclude/DNS lists when freeing vpninfo

Kevin Cernekee cernekee at gmail.com
Sun Aug 11 21:49:17 EDT 2013


Signed-off-by: Kevin Cernekee <cernekee at gmail.com>
---
 cstp.c                 |   41 +++++++++++++++++++++++------------------
 library.c              |    1 +
 openconnect-internal.h |    1 +
 3 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/cstp.c b/cstp.c
index 4c15d0d..af66fd8 100644
--- a/cstp.c
+++ b/cstp.c
@@ -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];
@@ -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 */
@@ -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 <
diff --git a/library.c b/library.c
index f4449a3..9b4cb89 100644
--- a/library.c
+++ b/library.c
@@ -132,6 +132,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);
diff --git a/openconnect-internal.h b/openconnect-internal.h
index 7ac3dda..7580264 100644
--- a/openconnect-internal.h
+++ b/openconnect-internal.h
@@ -410,6 +410,7 @@ int connect_dtls_socket(struct openconnect_info *vpninfo);
 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);
-- 
1.7.9.5




More information about the openconnect-devel mailing list