tests: transport: fix memory leaks with registering transports
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
diff --git a/tests/transport/register.c b/tests/transport/register.c
index 67a2efd..97aae6b 100644
--- a/tests/transport/register.c
+++ b/tests/transport/register.c
@@ -40,20 +40,23 @@ void test_transport_register__custom_transport_error_remove_non_existing(void)
void test_transport_register__custom_transport_ssh(void)
{
+ const char *urls[] = {
+ "ssh://somehost:somepath",
+ "ssh+git://somehost:somepath",
+ "git+ssh://somehost:somepath",
+ "git@somehost:somepath",
+ };
git_transport *transport;
+ unsigned i;
+ for (i = 0; i < ARRAY_SIZE(urls); i++) {
#ifndef GIT_SSH
- cl_git_fail_with(git_transport_new(&transport, NULL, "ssh://somehost:somepath"), -1);
- cl_git_fail_with(git_transport_new(&transport, NULL, "ssh+git://somehost:somepath"), -1);
- cl_git_fail_with(git_transport_new(&transport, NULL, "git+ssh://somehost:somepath"), -1);
- cl_git_fail_with(git_transport_new(&transport, NULL, "git@somehost:somepath"), -1);
+ cl_git_fail_with(git_transport_new(&transport, NULL, urls[i]), -1);
#else
- cl_git_pass(git_transport_new(&transport, NULL, "ssh://somehost:somepath"));
- cl_git_pass(git_transport_new(&transport, NULL, "ssh+git://somehost:somepath"));
- cl_git_pass(git_transport_new(&transport, NULL, "git+ssh://somehost:somepath"));
- cl_git_pass(git_transport_new(&transport, NULL, "git@somehost:somepath"));
- transport->free(transport);
+ cl_git_pass(git_transport_new(&transport, NULL, urls[i]));
+ transport->free(transport);
#endif
+ }
cl_git_pass(git_transport_register("ssh", dummy_transport, NULL));
@@ -63,16 +66,12 @@ void test_transport_register__custom_transport_ssh(void)
cl_git_pass(git_transport_unregister("ssh"));
+ for (i = 0; i < ARRAY_SIZE(urls); i++) {
#ifndef GIT_SSH
- cl_git_fail_with(git_transport_new(&transport, NULL, "ssh://somehost:somepath"), -1);
- cl_git_fail_with(git_transport_new(&transport, NULL, "ssh+git://somehost:somepath"), -1);
- cl_git_fail_with(git_transport_new(&transport, NULL, "git+ssh://somehost:somepath"), -1);
- cl_git_fail_with(git_transport_new(&transport, NULL, "git@somehost:somepath"), -1);
+ cl_git_fail_with(git_transport_new(&transport, NULL, urls[i]), -1);
#else
- cl_git_pass(git_transport_new(&transport, NULL, "ssh://somehost:somepath"));
- cl_git_pass(git_transport_new(&transport, NULL, "ssh+git://somehost:somepath"));
- cl_git_pass(git_transport_new(&transport, NULL, "git+ssh://somehost:somepath"));
- cl_git_pass(git_transport_new(&transport, NULL, "git@somehost:somepath"));
- transport->free(transport);
+ cl_git_pass(git_transport_new(&transport, NULL, urls[i]));
+ transport->free(transport);
#endif
+ }
}