[PATCH/RFC V2 19/26] main: Add openconnect_vpninfo_free() on a couple of exit paths

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


This makes it easier to check for library memory leaks.

Signed-off-by: Kevin Cernekee <cernekee at gmail.com>
---
 main.c |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/main.c b/main.c
index 53c5fae..82c73af 100644
--- a/main.c
+++ b/main.c
@@ -881,6 +881,7 @@ int main(int argc, char **argv)
 	}
 	if (openconnect_make_cstp_connection(vpninfo)) {
 		fprintf(stderr, _("Creating SSL connection failed\n"));
+		openconnect_vpninfo_free(vpninfo);
 		exit(1);
 	}
 
@@ -889,10 +890,12 @@ int main(int argc, char **argv)
 	if (script_tun) {
 		if (openconnect_setup_tun_script(vpninfo, vpnc_script)) {
 			fprintf(stderr, _("Set up tun script failed\n"));
+			openconnect_vpninfo_free(vpninfo);
 			exit(1);
 		}
 	} else if (openconnect_setup_tun_device(vpninfo, vpnc_script, ifname)) {
 		fprintf(stderr, _("Set up tun device failed\n"));
+		openconnect_vpninfo_free(vpninfo);
 		exit(1);
 	}
 
@@ -900,6 +903,7 @@ int main(int argc, char **argv)
 		if (setuid(uid)) {
 			fprintf(stderr, _("Failed to set uid %ld\n"),
 				(long)uid);
+			openconnect_vpninfo_free(vpninfo);
 			exit(1);
 		}
 	}
@@ -935,6 +939,7 @@ int main(int argc, char **argv)
 			if (!fp) {
 				fprintf(stderr, _("Failed to open '%s' for write: %s\n"),
 					pidfile, strerror(errno));
+				openconnect_vpninfo_free(vpninfo);
 				exit(1);
 			}
 		}
@@ -946,6 +951,7 @@ int main(int argc, char **argv)
 			vpn_progress(vpninfo, PRG_INFO,
 				     _("Continuing in background; pid %d\n"),
 				     pid);
+			openconnect_vpninfo_free(vpninfo);
 			exit(0);
 		}
 		if (fp)
@@ -958,6 +964,7 @@ int main(int argc, char **argv)
 
 	if (fp)
 		unlink(pidfile);
+	openconnect_vpninfo_free(vpninfo);
 	exit(1);
 }
 
-- 
1.7.9.5




More information about the openconnect-devel mailing list