summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2016-02-22 16:08:56 +0100
committerPatrick Steinhardt <ps@pks.im>2016-02-23 12:07:36 +0100
commit2baf854e975267eb560b48f1ead0641ec676d637 (patch)
tree1e29daf5c908f3c240286c266ecf900a3752b9d3
parent2afb6fa46df25ef77a166b92304cc6e725103c7c (diff)
downloadlibgit2-2baf854e975267eb560b48f1ead0641ec676d637.tar.gz
openssl_stream: fix memory leak when creating new stream
-rw-r--r--src/openssl_stream.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/openssl_stream.c b/src/openssl_stream.c
index 1dad5f637..840e7dc3f 100644
--- a/src/openssl_stream.c
+++ b/src/openssl_stream.c
@@ -545,6 +545,7 @@ int git_openssl_stream_new(git_stream **out, const char *host, const char *port)
st = git__calloc(1, sizeof(openssl_stream));
GITERR_CHECK_ALLOC(st);
+ st->io = NULL;
#ifdef GIT_CURL
error = git_curl_stream_new(&st->io, host, port);
#else
@@ -552,12 +553,13 @@ int git_openssl_stream_new(git_stream **out, const char *host, const char *port)
#endif
if (error < 0)
- return error;
+ goto out_err;
st->ssl = SSL_new(git__ssl_ctx);
if (st->ssl == NULL) {
giterr_set(GITERR_SSL, "failed to create ssl object");
- return -1;
+ error = -1;
+ goto out_err;
}
st->host = git__strdup(host);
@@ -576,6 +578,12 @@ int git_openssl_stream_new(git_stream **out, const char *host, const char *port)
*out = (git_stream *) st;
return 0;
+
+out_err:
+ git_stream_free(st->io);
+ git__free(st);
+
+ return error;
}
#else