Commit a28889198cf9565944aa0ff983459c6bf6eec311

Carlos Martín Nieto 2011-09-30T18:35:33

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>

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;