local transport: don't segfault on wrong URL memset the structure on initialisation and don't try to dereference the vector with the heads if we didn't find a repository. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
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
diff --git a/src/transport_local.c b/src/transport_local.c
index 4975af9..7e932f8 100644
--- a/src/transport_local.c
+++ b/src/transport_local.c
@@ -201,16 +201,19 @@ static void local_free(git_transport *transport)
unsigned int i;
transport_local *t = (transport_local *) transport;
git_vector *vec = t->refs;
+ git_remote_head *h;
assert(transport);
- for (i = 0; i < vec->length; ++i) {
- git_remote_head *h = git_vector_get(vec, i);
- free(h->name);
- free(h);
+ if (t->refs != NULL) {
+ git_vector_foreach (vec, i, h) {
+ free(h->name);
+ free(h);
+ }
+ git_vector_free(vec);
+ free(vec);
}
- git_vector_free(vec);
- free(vec);
+
git_repository_free(t->repo);
free(t->parent.url);
free(t);
@@ -228,6 +231,8 @@ int git_transport_local(git_transport **out)
if (t == NULL)
return GIT_ENOMEM;
+ memset(t, 0x0, sizeof(transport_local));
+
t->parent.connect = local_connect;
t->parent.ls = local_ls;
t->parent.send_wants = local_send_wants;