Merged pull request #135 from carlosmn/valgrind. Fix memory leaks in the tests
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
diff --git a/tests/t04-commit.c b/tests/t04-commit.c
index bcc0417..3e02df9 100644
--- a/tests/t04-commit.c
+++ b/tests/t04-commit.c
@@ -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
diff --git a/tests/t09-tree.c b/tests/t09-tree.c
index bd88642..9b39dfd 100644
--- a/tests/t09-tree.c
+++ b/tests/t09-tree.c
@@ -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
diff --git a/tests/t10-refs.c b/tests/t10-refs.c
index a6a5601..d3f5620 100644
--- a/tests/t10-refs.c
+++ b/tests/t10-refs.c
@@ -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
diff --git a/tests/test_lib.c b/tests/test_lib.c
index c9c6141..5778404 100755
--- a/tests/test_lib.c
+++ b/tests/test_lib.c
@@ -130,6 +130,7 @@ static void free_suite(git_testsuite *ts)
if (ts->list[n])
test_free(ts->list[n]);
+ free(ts->name);
free(ts);
}