Commit f95fe9a3 authored by David Woodhouse's avatar David Woodhouse

Fix up some more memory leaks

Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent ad37c0ad
......@@ -972,8 +972,8 @@ static int handle_redirect(struct openconnect_info *vpninfo)
openconnect_close_https(vpninfo, 0);
openconnect_clear_cookies(vpninfo);
vpninfo->redirect_type = REDIR_TYPE_NEWHOST;
} else
free(host);
}
free(host);
free(vpninfo->redirect_url);
vpninfo->redirect_url = NULL;
......@@ -1269,6 +1269,7 @@ newgroup:
method = "GET";
if (orig_host) {
openconnect_set_hostname(vpninfo, orig_host);
free(orig_host);
orig_host = NULL;
free(vpninfo->urlpath);
vpninfo->urlpath = orig_path;
......
......@@ -185,6 +185,7 @@ void openconnect_vpninfo_free(struct openconnect_info *vpninfo)
free_optlist(vpninfo->dtls_options);
cstp_free_splits(vpninfo);
free(vpninfo->hostname);
free(vpninfo->unique_hostname);
free(vpninfo->urlpath);
free(vpninfo->redirect_url);
free(vpninfo->cookie);
......@@ -277,7 +278,6 @@ int openconnect_set_hostname(struct openconnect_info *vpninfo,
{
UTF8CHECK(hostname);
free(vpninfo->hostname);
STRDUP(vpninfo->hostname, hostname);
free(vpninfo->unique_hostname);
vpninfo->unique_hostname = NULL;
......@@ -384,6 +384,10 @@ int openconnect_set_client_cert(struct openconnect_info *vpninfo,
UTF8CHECK(cert);
UTF8CHECK(sslkey);
/* Avoid freeing it twice if it's the same */
if (vpninfo->sslkey == vpninfo->cert)
vpninfo->sslkey = NULL;
STRDUP(vpninfo->cert, cert);
if (sslkey) {
......
......@@ -236,8 +236,8 @@ struct openconnect_info {
int port;
char *urlpath;
int cert_expire_warning;
const char *cert;
const char *sslkey;
char *cert;
char *sslkey;
char *cert_password;
char *cafile;
unsigned no_system_trust;
......@@ -724,10 +724,13 @@ int digest_authorization(struct openconnect_info *vpninfo, struct oc_text_buf *b
extern const char *openconnect_version_str;
#define STRDUP(res, arg) \
if (arg) { \
res = strdup(arg); \
if (res == NULL) return -ENOMEM; \
} else res = NULL
do { \
free(res); \
if (arg) { \
res = strdup(arg); \
if (res == NULL) return -ENOMEM; \
} else res = NULL; \
} while(0)
#define UTF8CHECK(arg) \
if ((arg) && buf_append_utf16le(NULL, (arg))) { \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment