Remove double-free segfaults
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
diff --git a/src/transports/git.c b/src/transports/git.c
index 21de4d7..a36a0a7 100644
--- a/src/transports/git.c
+++ b/src/transports/git.c
@@ -179,7 +179,7 @@ static int _git_uploadpack_ls(
const char *url,
git_smart_subtransport_stream **stream)
{
- char *host, *port, *user, *pass;
+ char *host, *port, *user=NULL, *pass=NULL;
git_stream *s;
*stream = NULL;
@@ -201,8 +201,8 @@ static int _git_uploadpack_ls(
t->current_stream = s;
git__free(host);
git__free(port);
- git__free(user);
- git__free(pass);
+ if (user) git__free(user);
+ if (pass) git__free(pass);
return 0;
on_error:
@@ -235,7 +235,7 @@ static int _git_receivepack_ls(
const char *url,
git_smart_subtransport_stream **stream)
{
- char *host, *port, *user, *pass;
+ char *host, *port, *user=NULL, *pass=NULL;
git_stream *s;
*stream = NULL;
@@ -257,8 +257,8 @@ static int _git_receivepack_ls(
t->current_stream = s;
git__free(host);
git__free(port);
- git__free(user);
- git__free(pass);
+ if (user) git__free(user);
+ if (pass) git__free(pass);
return 0;
on_error: