mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 07:20:07 +00:00
tests: don't leak objects
If we don't create any leaks in the tests, we can use them to search for leaks in the implementation. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
This commit is contained in:
parent
fdd0cc9e89
commit
2fe3692c23
@ -368,7 +368,7 @@ BEGIN_TEST(details0, "query the details on a parsed commit")
|
||||
const char *message, *message_short;
|
||||
git_time_t commit_time;
|
||||
unsigned int parents, p;
|
||||
git_commit *parent;
|
||||
git_commit *parent = NULL, *old_parent = NULL;
|
||||
|
||||
git_oid_mkstr(&id, commit_ids[i]);
|
||||
|
||||
@ -390,11 +390,19 @@ BEGIN_TEST(details0, "query the details on a parsed commit")
|
||||
must_be_true(commit_time > 0);
|
||||
must_be_true(parents <= 2);
|
||||
for (p = 0;p < parents;p++) {
|
||||
if (old_parent != NULL)
|
||||
git_commit_close(old_parent);
|
||||
|
||||
old_parent = parent;
|
||||
must_pass(git_commit_parent(&parent, commit, p));
|
||||
must_be_true(parent != NULL);
|
||||
must_be_true(git_commit_author(parent) != NULL); // is it really a commit?
|
||||
}
|
||||
git_commit_close(old_parent);
|
||||
git_commit_close(parent);
|
||||
|
||||
must_fail(git_commit_parent(&parent, commit, parents));
|
||||
git_commit_close(commit);
|
||||
}
|
||||
|
||||
git_repository_free(repo);
|
||||
@ -462,6 +470,7 @@ BEGIN_TEST(write0, "write a new commit object from memory to disk")
|
||||
|
||||
must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit));
|
||||
|
||||
git_commit_close(commit);
|
||||
git_repository_free(repo);
|
||||
END_TEST
|
||||
|
||||
|
@ -82,6 +82,7 @@ BEGIN_TEST(read0, "acces randomly the entries on a loaded tree")
|
||||
must_be_true(git_tree_entry_byindex(tree, 3) == NULL);
|
||||
must_be_true(git_tree_entry_byindex(tree, -1) == NULL);
|
||||
|
||||
git_tree_close(tree);
|
||||
git_repository_free(repo);
|
||||
END_TEST
|
||||
|
||||
@ -102,7 +103,9 @@ BEGIN_TEST(read1, "read a tree from the repository")
|
||||
|
||||
/* GH-86: git_object_lookup() should also check the type if the object comes from the cache */
|
||||
must_be_true(git_object_lookup(&obj, repo, &id, GIT_OBJ_TREE) == 0);
|
||||
git_object_close(obj);
|
||||
must_be_true(git_object_lookup(&obj, repo, &id, GIT_OBJ_BLOB) == GIT_EINVALIDTYPE);
|
||||
git_object_close(obj);
|
||||
|
||||
entry = git_tree_entry_byname(tree, "README");
|
||||
must_be_true(entry != NULL);
|
||||
@ -111,6 +114,8 @@ BEGIN_TEST(read1, "read a tree from the repository")
|
||||
|
||||
must_pass(git_tree_entry_2object(&obj, repo, entry));
|
||||
|
||||
git_object_close(obj);
|
||||
git_tree_close(tree);
|
||||
git_repository_free(repo);
|
||||
END_TEST
|
||||
|
||||
@ -148,6 +153,9 @@ BEGIN_TEST(write2, "write a tree from a memory")
|
||||
must_pass(git_treebuilder_write(&rid,repo,builder));
|
||||
|
||||
must_be_true(git_oid_cmp(&rid, &id2) == 0);
|
||||
|
||||
git_treebuilder_free(builder);
|
||||
git_tree_close(tree);
|
||||
close_temp_repo(repo);
|
||||
END_TEST
|
||||
|
||||
|
@ -51,6 +51,7 @@ BEGIN_TEST(readtag0, "lookup a loose tag reference")
|
||||
git__joinpath(ref_name_from_tag_name, GIT_REFS_TAGS_DIR, git_tag_name((git_tag *)object));
|
||||
must_be_true(strcmp(ref_name_from_tag_name, loose_tag_ref_name) == 0);
|
||||
|
||||
git_object_close(object);
|
||||
git_repository_free(repo);
|
||||
END_TEST
|
||||
|
||||
@ -91,6 +92,7 @@ BEGIN_TEST(readsym0, "lookup a symbolic reference")
|
||||
git_oid_mkstr(&id, current_master_tip);
|
||||
must_be_true(git_oid_cmp(&id, git_object_id(object)) == 0);
|
||||
|
||||
git_object_close(object);
|
||||
git_repository_free(repo);
|
||||
END_TEST
|
||||
|
||||
@ -117,6 +119,7 @@ BEGIN_TEST(readsym1, "lookup a nested symbolic reference")
|
||||
git_oid_mkstr(&id, current_master_tip);
|
||||
must_be_true(git_oid_cmp(&id, git_object_id(object)) == 0);
|
||||
|
||||
git_object_close(object);
|
||||
git_repository_free(repo);
|
||||
END_TEST
|
||||
|
||||
@ -175,6 +178,7 @@ BEGIN_TEST(readpacked0, "lookup a packed reference")
|
||||
must_be_true(object != NULL);
|
||||
must_be_true(git_object_type(object) == GIT_OBJ_COMMIT);
|
||||
|
||||
git_object_close(object);
|
||||
git_repository_free(repo);
|
||||
END_TEST
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user