Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix up some more memory leaks
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Nov 4, 2014
1 parent ad37c0a commit f95fe9a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
5 changes: 3 additions & 2 deletions http.c
Expand Up @@ -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;
Expand Down Expand Up @@ -1269,6 +1269,7 @@ int openconnect_obtain_cookie(struct openconnect_info *vpninfo)
method = "GET";
if (orig_host) {
openconnect_set_hostname(vpninfo, orig_host);
free(orig_host);
orig_host = NULL;
free(vpninfo->urlpath);
vpninfo->urlpath = orig_path;
Expand Down
6 changes: 5 additions & 1 deletion library.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 9 additions & 6 deletions openconnect-internal.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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))) { \
Expand Down

0 comments on commit f95fe9a

Please sign in to comment.