Commit 21e6a11a55fc2ca0f7385ef2f43cd75090a10d5f

Edward Thomson 2017-10-07T12:55:16

Merge pull request #4359 from libgit2/cmn/proxy-options-free Plug some leaks in curl's proxy handling

diff --git a/src/curl_stream.c b/src/curl_stream.c
index 24bf626..a895cb8 100644
--- a/src/curl_stream.c
+++ b/src/curl_stream.c
@@ -195,6 +195,7 @@ static int curls_set_proxy(git_stream *stream, const git_proxy_options *proxy_op
 	CURLcode res;
 	curl_stream *s = (curl_stream *) stream;
 
+	git_proxy_options_clear(&s->proxy);
 	if ((error = git_proxy_options_dup(&s->proxy, proxy_opts)) < 0)
 		return error;
 
@@ -295,6 +296,8 @@ static void curls_free(git_stream *stream)
 
 	curls_close(stream);
 	git_strarray_free(&s->cert_info_strings);
+	git_proxy_options_clear(&s->proxy);
+	git_cred_free(s->proxy_cred);
 	git__free(s);
 }
 
diff --git a/src/proxy.c b/src/proxy.c
index b07371d..9bc2c7f 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -31,3 +31,9 @@ int git_proxy_options_dup(git_proxy_options *tgt, const git_proxy_options *src)
 
 	return 0;
 }
+
+void git_proxy_options_clear(git_proxy_options *opts)
+{
+	git__free((char *) opts->url);
+	opts->url = NULL;
+}
diff --git a/src/proxy.h b/src/proxy.h
index 7582301..f8b5c4b 100644
--- a/src/proxy.h
+++ b/src/proxy.h
@@ -12,5 +12,6 @@
 #include "git2/proxy.h"
 
 extern int git_proxy_options_dup(git_proxy_options *tgt, const git_proxy_options *src);
+extern void git_proxy_options_clear(git_proxy_options *opts);
 
 #endif