Stop premature remote freeing when cloning
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 60 61 62 63 64 65 66 67 68 69 70 71 72
diff --git a/examples/network/clone.c b/examples/network/clone.c
index 52146a2..f8a5ec4 100644
--- a/examples/network/clone.c
+++ b/examples/network/clone.c
@@ -82,6 +82,7 @@ int do_clone(git_repository *repo, int argc, char **argv)
// Do the clone
error = git_clone(&cloned_repo, origin, path, &checkout_opts, &fetch_progress, &pd);
+ git_remote_free(origin);
printf("\n");
if (error != 0) {
const git_error *err = giterr_last();
diff --git a/src/clone.c b/src/clone.c
index 55638fd..aa6c43f 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -289,7 +289,6 @@ static int setup_remotes_and_fetch(
}
git_remote_disconnect(origin);
}
- git_remote_free(origin);
}
return retcode;
diff --git a/tests-clar/clone/network.c b/tests-clar/clone/network.c
index 018f464..15ad95b 100644
--- a/tests-clar/clone/network.c
+++ b/tests-clar/clone/network.c
@@ -17,6 +17,12 @@ void test_clone_network__initialize(void)
cl_git_pass(git_remote_new(&g_origin, NULL, "origin", LIVE_REPO_URL, GIT_REMOTE_DEFAULT_FETCH));
}
+void test_clone_network__cleanup(void)
+{
+ git_remote_free(g_origin);
+ g_origin = NULL;
+}
+
static void cleanup_repository(void *path)
{
if (g_repo) {
diff --git a/tests-clar/clone/nonetwork.c b/tests-clar/clone/nonetwork.c
index af12981..373b296 100644
--- a/tests-clar/clone/nonetwork.c
+++ b/tests-clar/clone/nonetwork.c
@@ -14,6 +14,12 @@ void test_clone_nonetwork__initialize(void)
cl_git_pass(git_remote_new(&g_origin, NULL, "origin", cl_git_fixture_url("testrepo.git"), GIT_REMOTE_DEFAULT_FETCH));
}
+void test_clone_nonetwork__cleanup(void)
+{
+ git_remote_free(g_origin);
+ g_origin = NULL;
+}
+
static void cleanup_repository(void *path)
{
if (g_repo) {
@@ -56,7 +62,6 @@ void test_clone_nonetwork__fail_when_the_target_is_a_file(void)
cl_git_mkfile("./foo", "Bar!");
cl_git_fail(git_clone(&g_repo, g_origin, "./foo", NULL, NULL, NULL));
- git_remote_free(g_origin);
}
void test_clone_nonetwork__fail_with_already_existing_but_non_empty_directory(void)
@@ -66,5 +71,4 @@ void test_clone_nonetwork__fail_with_already_existing_but_non_empty_directory(vo
p_mkdir("./foo", GIT_DIR_MODE);
cl_git_mkfile("./foo/bar", "Baz!");
cl_git_fail(git_clone(&g_repo, g_origin, "./foo", NULL, NULL, NULL));
- git_remote_free(g_origin);
}