mirror of
https://git.proxmox.com/git/libgit2
synced 2026-01-07 07:52:16 +00:00
Plug a bunch of leaks
This commit is contained in:
parent
a5123ea80b
commit
89886d0bbb
11
src/index.c
11
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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -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"));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user