Commit 088a731f by Vicent Marti

Fixed memory leaks in test suite

Created commit objects in t0401-parse weren't being freed properly.
Updated the API documentation to note that commit objects are owned
by the revision pool and should not be freed manually.

The parents list of each commit was being freed twice after each test.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
parent 58b0cbea
...@@ -204,7 +204,7 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len) ...@@ -204,7 +204,7 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len)
if (commit->uninteresting) if (commit->uninteresting)
parent->uninteresting = 1; parent->uninteresting = 1;
if (git_commit_list_push_back(&commit->parents, parent)) if (git_commit_list_push_back(&commit->parents, parent) < 0)
return GIT_ENOMEM; return GIT_ENOMEM;
} }
......
...@@ -18,6 +18,9 @@ typedef struct git_commit git_commit; ...@@ -18,6 +18,9 @@ typedef struct git_commit git_commit;
/** /**
* Locate a reference to a commit without loading it. * Locate a reference to a commit without loading it.
* The generated commit object is owned by the revision
* pool and shall not be freed by the user.
*
* @param pool the pool to use when locating the commit. * @param pool the pool to use when locating the commit.
* @param id identity of the commit to locate. If the object is * @param id identity of the commit to locate. If the object is
* an annotated tag it will be peeled back to the commit. * an annotated tag it will be peeled back to the commit.
...@@ -28,6 +31,9 @@ GIT_EXTERN(git_commit *) git_commit_lookup(git_revpool *pool, const git_oid *id) ...@@ -28,6 +31,9 @@ GIT_EXTERN(git_commit *) git_commit_lookup(git_revpool *pool, const git_oid *id)
/** /**
* Locate a reference to a commit, and try to load and parse it it from * Locate a reference to a commit, and try to load and parse it it from
* the commit cache or the object database. * the commit cache or the object database.
* The generated commit object is owned by the revision
* pool and shall not be freed by the user.
*
* @param pool the pool to use when parsing/caching the commit. * @param pool the pool to use when parsing/caching the commit.
* @param id identity of the commit to locate. If the object is * @param id identity of the commit to locate. If the object is
* an annotated tag it will be peeled back to the commit. * an annotated tag it will be peeled back to the commit.
......
...@@ -54,6 +54,7 @@ void gitrp_free(git_revpool *walk) ...@@ -54,6 +54,7 @@ void gitrp_free(git_revpool *walk)
git_revpool_tableit_init(walk->commits, &it); git_revpool_tableit_init(walk->commits, &it);
while ((commit = (git_commit *)git_revpool_tableit_next(&it)) != NULL) { while ((commit = (git_commit *)git_revpool_tableit_next(&it)) != NULL) {
git_commit_list_clear(&commit->parents, 0);
free(commit); free(commit);
} }
......
...@@ -151,6 +151,8 @@ BEGIN_TEST(parse_buffer_test) ...@@ -151,6 +151,8 @@ BEGIN_TEST(parse_buffer_test)
test_commits_broken[i], test_commits_broken[i],
strlen(test_commits_broken[i])) strlen(test_commits_broken[i]))
); );
git_commit_list_clear(&commit.parents, 0);
} }
for (i = 0; i < working_commit_count; ++i) { for (i = 0; i < working_commit_count; ++i) {
...@@ -163,6 +165,8 @@ BEGIN_TEST(parse_buffer_test) ...@@ -163,6 +165,8 @@ BEGIN_TEST(parse_buffer_test)
test_commits_working[i], test_commits_working[i],
strlen(test_commits_working[i])) strlen(test_commits_working[i]))
); );
git_commit_list_clear(&commit.parents, 0);
} }
gitrp_free(pool); gitrp_free(pool);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment