]> git.proxmox.com Git - libgit2.git/commitdiff
tests: don't leak objects
authorCarlos Martín Nieto <cmn@elego.de>
Wed, 13 Apr 2011 15:44:08 +0000 (17:44 +0200)
committerCarlos Martín Nieto <cmn@elego.de>
Wed, 13 Apr 2011 19:50:11 +0000 (21:50 +0200)
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>
tests/t04-commit.c
tests/t09-tree.c
tests/t10-refs.c

index bcc0417c835e6fad93f84a83ba6f4b730680cbee..3e02df996c0a685560dccb772f45be2b5fed5114 100644 (file)
@@ -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
 
index bd88642fadb907f1a3a5494cf1dcca2d76c0b6a2..9b39dfd07fccae03d0469d6970a683709ca82f84 100644 (file)
@@ -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
 
index a6a56019372747a709af3e8a24f94b6ee3680c1d..d3f5620c950ffa58f2fc79be02f461bc69d51cd8 100644 (file)
@@ -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