Plug a bunch of leaks
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
diff --git a/src/index.c b/src/index.c
index d01262b..9f336ba 100644
--- a/src/index.c
+++ b/src/index.c
@@ -87,6 +87,8 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
static int is_index_extended(git_index *index);
static int write_index(git_index *index, git_filebuf *file);
+static void index_entry_free(git_index_entry *entry);
+
static int index_srch(const void *key, const void *array_member)
{
const git_index_entry *entry = array_member;
@@ -157,8 +159,17 @@ int git_index_open(git_index **index_out, const char *index_path)
static void index_free(git_index *index)
{
+ git_index_entry *e;
+ unsigned int i;
+
git_index_clear(index);
+ git_vector_foreach(&index->entries, i, e) {
+ index_entry_free(e);
+ }
git_vector_free(&index->entries);
+ git_vector_foreach(&index->unmerged, i, e) {
+ index_entry_free(e);
+ }
git_vector_free(&index->unmerged);
git__free(index->index_file_path);
diff --git a/src/status.c b/src/status.c
index 97093a5..26dd11e 100644
--- a/src/status.c
+++ b/src/status.c
@@ -154,6 +154,7 @@ static int retrieve_head_tree(git_tree **tree_out, git_repository *repo)
if ((error = git_commit_lookup(&head_commit, repo, git_reference_oid(resolved_head_ref))) < GIT_SUCCESS)
return git__rethrow(error, "The tip of HEAD can't be retrieved");
+ git_reference_free(resolved_head_ref);
if ((error = git_commit_tree(&tree, head_commit)) < GIT_SUCCESS) {
error = git__rethrow(error, "The tree of HEAD can't be retrieved");
goto exit;
diff --git a/tests-clay/repo/getters.c b/tests-clay/repo/getters.c
index 3acdb75..426b83e 100644
--- a/tests-clay/repo/getters.c
+++ b/tests-clay/repo/getters.c
@@ -37,6 +37,7 @@ void test_repo_getters__head_detached(void)
git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd");
cl_git_pass(git_reference_create_oid(&ref, repo, "HEAD", &oid, 1));
cl_assert(git_repository_head_detached(repo) == 1);
+ git_reference_free(ref);
/* take the reop back to it's original state */
cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1));
@@ -58,6 +59,7 @@ void test_repo_getters__head_orphan(void)
/* orphan HEAD */
cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/orphan", 1));
cl_assert(git_repository_head_orphan(repo) == 1);
+ git_reference_free(ref);
/* take the reop back to it's original state */
cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1));
diff --git a/tests/t04-commit.c b/tests/t04-commit.c
index a0e6037..82eb983 100644
--- a/tests/t04-commit.c
+++ b/tests/t04-commit.c
@@ -759,6 +759,7 @@ BEGIN_TEST(root0, "create a root commit")
must_be_true(!strcmp(git_commit_message(commit), ROOT_COMMIT_MESSAGE));
/* Remove the data we just added to the repo */
+ git_reference_free(head);
must_pass(git_reference_lookup(&head, repo, "HEAD"));
must_pass(git_reference_set_target(head, head_old));
must_pass(git_reference_delete(branch));
diff --git a/tests/t08-tag.c b/tests/t08-tag.c
index 47d7be8..eacbb3a 100644
--- a/tests/t08-tag.c
+++ b/tests/t08-tag.c
@@ -243,6 +243,7 @@ BEGIN_TEST(write3, "Replace an already existing tag")
must_pass(git_reference_lookup(&ref_tag, repo, "refs/tags/e90810b"));
git_oid_cpy(&old_tag_id, git_reference_oid(ref_tag));
+ git_reference_free(ref_tag);
/* create signature */
must_pass(git_signature_new(&tagger, TAGGER_NAME, TAGGER_EMAIL, 123456789, 60));
diff --git a/tests/t10-refs.c b/tests/t10-refs.c
index b00ccfa..3cfba58 100644
--- a/tests/t10-refs.c
+++ b/tests/t10-refs.c
@@ -212,6 +212,7 @@ BEGIN_TEST(readpacked1, "assure that a loose reference is looked up before a pac
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_reference_lookup(&reference, repo, packed_head_name));
+ git_reference_free(reference);
must_pass(git_reference_lookup(&reference, repo, packed_test_head_name));
must_be_true(git_reference_type(reference) & GIT_REF_OID);
must_be_true(git_reference_is_packed(reference) == 0);
@@ -252,6 +253,8 @@ BEGIN_TEST(create0, "create a new symbolic reference")
/* ...and that it points to the current master tip */
must_be_true(git_oid_cmp(&id, git_reference_oid(resolved_ref)) == 0);
+ git_reference_free(looked_up_ref);
+ git_reference_free(resolved_ref);
git_repository_free(repo);
@@ -320,6 +323,7 @@ BEGIN_TEST(create2, "create a new OID reference")
/* ...and that it points to the current master tip */
must_be_true(git_oid_cmp(&id, git_reference_oid(looked_up_ref)) == 0);
+ git_reference_free(looked_up_ref);
git_repository_free(repo);
@@ -368,14 +372,18 @@ BEGIN_TEST(overwrite0, "Overwrite an existing symbolic reference")
/* The target needds to exist and we need to check the name has changed */
must_pass(git_reference_create_symbolic(&branch_ref, repo, ref_branch_name, ref_master_name, 0));
must_pass(git_reference_create_symbolic(&ref, repo, ref_name, ref_branch_name, 0));
+ git_reference_free(ref);
+
/* Ensure it points to the right place*/
must_pass(git_reference_lookup(&ref, repo, ref_name));
must_be_true(git_reference_type(ref) & GIT_REF_SYMBOLIC);
must_be_true(!strcmp(git_reference_target(ref), ref_branch_name));
+ git_reference_free(ref);
/* Ensure we can't create it unless we force it to */
must_fail(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name, 0));
must_pass(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name, 1));
+ git_reference_free(ref);
/* Ensure it points to the right place */
must_pass(git_reference_lookup(&ref, repo, ref_name));
@@ -398,17 +406,21 @@ BEGIN_TEST(overwrite1, "Overwrite an existing object id reference")
must_pass(git_reference_lookup(&ref, repo, ref_master_name));
must_be_true(git_reference_type(ref) & GIT_REF_OID);
git_oid_cpy(&id, git_reference_oid(ref));
+ git_reference_free(ref);
/* Create it */
must_pass(git_reference_create_oid(&ref, repo, ref_name, &id, 0));
+ git_reference_free(ref);
must_pass(git_reference_lookup(&ref, repo, ref_test_name));
must_be_true(git_reference_type(ref) & GIT_REF_OID);
git_oid_cpy(&id, git_reference_oid(ref));
+ git_reference_free(ref);
/* Ensure we can't overwrite unless we force it */
must_fail(git_reference_create_oid(&ref, repo, ref_name, &id, 0));
must_pass(git_reference_create_oid(&ref, repo, ref_name, &id, 1));
+ git_reference_free(ref);
/* Ensure it has been overwritten */
must_pass(git_reference_lookup(&ref, repo, ref_name));
@@ -429,10 +441,13 @@ BEGIN_TEST(overwrite2, "Overwrite an existing object id reference with a symboli
must_pass(git_reference_lookup(&ref, repo, ref_master_name));
must_be_true(git_reference_type(ref) & GIT_REF_OID);
git_oid_cpy(&id, git_reference_oid(ref));
+ git_reference_free(ref);
must_pass(git_reference_create_oid(&ref, repo, ref_name, &id, 0));
+ git_reference_free(ref);
must_fail(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name, 0));
must_pass(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name, 1));
+ git_reference_free(ref);
/* Ensure it points to the right place */
must_pass(git_reference_lookup(&ref, repo, ref_name));
@@ -454,12 +469,15 @@ BEGIN_TEST(overwrite3, "Overwrite an existing symbolic reference with an object
must_pass(git_reference_lookup(&ref, repo, ref_master_name));
must_be_true(git_reference_type(ref) & GIT_REF_OID);
git_oid_cpy(&id, git_reference_oid(ref));
+ git_reference_free(ref);
/* Create the symbolic ref */
must_pass(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name, 0));
+ git_reference_free(ref);
/* It shouldn't overwrite unless we tell it to */
must_fail(git_reference_create_oid(&ref, repo, ref_name, &id, 0));
must_pass(git_reference_create_oid(&ref, repo, ref_name, &id, 1));
+ git_reference_free(ref);
/* Ensure it points to the right place */
must_pass(git_reference_lookup(&ref, repo, ref_name));
@@ -496,6 +514,7 @@ BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo")
must_pass(git_reference_lookup(&reference, repo, loose_tag_ref_name));
must_be_true(git_reference_is_packed(reference) == 0);
must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0);
+ git_reference_free(reference);
/*
* We are now trying to pack also a loose reference
@@ -625,6 +644,7 @@ BEGIN_TEST(rename2, "renaming a packed reference does not pack another reference
/* Ensure it's loose */
must_be_true(git_reference_is_packed(another_looked_up_ref) == 0);
+ git_reference_free(another_looked_up_ref);
/* Lookup the reference to rename */
must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name));
@@ -661,6 +681,7 @@ BEGIN_TEST(rename3, "can not rename a reference with the name of an existing ref
/* Can not be renamed to the name of another existing reference. */
must_fail(git_reference_rename(looked_up_ref, packed_test_head_name, 0));
+ git_reference_free(looked_up_ref);
/* Failure to rename it hasn't corrupted its state */
must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name));
@@ -687,6 +708,7 @@ BEGIN_TEST(rename4, "can not rename a reference with an invalid name")
must_fail(git_reference_rename(looked_up_ref, "i-will-sudo-you", 0));
/* Failure to rename it hasn't corrupted its state */
+ git_reference_free(looked_up_ref);
must_pass(git_reference_lookup(&looked_up_ref, repo, packed_test_head_name));
must_be_true(!strcmp(looked_up_ref->name, packed_test_head_name));
@@ -708,18 +730,18 @@ BEGIN_TEST(rename5, "can force-rename a packed reference with the name of an exi
/* Can be force-renamed to the name of another existing reference. */
must_pass(git_reference_rename(looked_up_ref, packed_test_head_name, 1));
+ git_reference_free(looked_up_ref);
/* Check we actually renamed it */
must_pass(git_reference_lookup(&looked_up_ref, repo, packed_test_head_name));
must_be_true(!strcmp(looked_up_ref->name, packed_test_head_name));
must_be_true(!git_oid_cmp(&oid, git_reference_oid(looked_up_ref)));
+ git_reference_free(looked_up_ref);
/* And that the previous one doesn't exist any longer */
must_fail(git_reference_lookup(&looked_up_ref, repo, packed_head_name));
close_temp_repo(repo);
-
- git_reference_free(looked_up_ref);
END_TEST
BEGIN_TEST(rename6, "can force-rename a loose reference with the name of an existing loose reference")
@@ -734,12 +756,14 @@ BEGIN_TEST(rename6, "can force-rename a loose reference with the name of an exis
git_oid_cpy(&oid, git_reference_oid(looked_up_ref));
/* Can be force-renamed to the name of another existing reference. */
- must_pass(git_reference_rename(looked_up_ref, "refs/heads/test", 1));
+must_pass(git_reference_rename(looked_up_ref, "refs/heads/test", 1));
+ git_reference_free(looked_up_ref);
/* Check we actually renamed it */
must_pass(git_reference_lookup(&looked_up_ref, repo, "refs/heads/test"));
must_be_true(!strcmp(looked_up_ref->name, "refs/heads/test"));
must_be_true(!git_oid_cmp(&oid, git_reference_oid(looked_up_ref)));
+ git_reference_free(looked_up_ref);
/* And that the previous one doesn't exist any longer */
must_fail(git_reference_lookup(&looked_up_ref, repo, "refs/heads/br2"));
@@ -808,10 +832,12 @@ BEGIN_TEST(rename8, "can be renamed to a new name prefixed with the old name")
/* Can be rename to a new name starting with the old name. */
must_pass(git_reference_rename(looked_up_ref, ref_two_name_new, 0));
+ git_reference_free(looked_up_ref);
/* Check we actually renamed it */
must_pass(git_reference_lookup(&looked_up_ref, repo, ref_two_name_new));
must_be_true(!strcmp(looked_up_ref->name, ref_two_name_new));
+ git_reference_free(looked_up_ref);
must_fail(git_reference_lookup(&looked_up_ref, repo, ref_two_name));
close_temp_repo(repo);
@@ -835,17 +861,22 @@ BEGIN_TEST(rename9, "can move a reference to a upper reference hierarchy")
/* Create loose references */
must_pass(git_reference_create_oid(&ref_two, repo, ref_two_name_new, &id, 0));
+ git_reference_free(ref_two);
/* An existing reference... */
must_pass(git_reference_lookup(&looked_up_ref, repo, ref_two_name_new));
/* Can be renamed upward the reference tree. */
must_pass(git_reference_rename(looked_up_ref, ref_two_name, 0));
+ git_reference_free(looked_up_ref);
/* Check we actually renamed it */
must_pass(git_reference_lookup(&looked_up_ref, repo, ref_two_name));
must_be_true(!strcmp(looked_up_ref->name, ref_two_name));
+ git_reference_free(looked_up_ref);
must_fail(git_reference_lookup(&looked_up_ref, repo, ref_two_name_new));
+ git_reference_free(ref);
+ git_reference_free(looked_up_ref);
close_temp_repo(repo);
END_TEST
@@ -893,6 +924,7 @@ BEGIN_TEST(delete1, "can delete a just packed reference")
/* Create and write the new object id reference */
must_pass(git_reference_create_oid(&ref, repo, new_ref, &id, 0));
+ git_reference_free(ref);
/* Lookup the reference */
must_pass(git_reference_lookup(&ref, repo, new_ref));
@@ -1168,6 +1200,7 @@ BEGIN_TEST(reflog0, "write a reflog for a given reference and ensure it can be r
/* Create a new branch pointing at the HEAD */
git_oid_fromstr(&oid, current_master_tip);
must_pass(git_reference_create_oid(&ref, repo, new_ref, &oid, 0));
+ git_reference_free(ref);
must_pass(git_reference_lookup(&ref, repo, new_ref));
must_pass(git_signature_now(&committer, "foo", "foo@bar"));
@@ -1224,6 +1257,7 @@ BEGIN_TEST(reflog1, "avoid writing an obviously wrong reflog")
/* Create a new branch pointing at the HEAD */
git_oid_fromstr(&oid, current_master_tip);
must_pass(git_reference_create_oid(&ref, repo, new_ref, &oid, 0));
+ git_reference_free(ref);
must_pass(git_reference_lookup(&ref, repo, new_ref));
must_pass(git_signature_now(&committer, "foo", "foo@bar"));