Commit 088a731f00a39fb3158dc9150b7c8d176df51867

Vicent Marti 2010-06-09T14:54:22

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>

diff --git a/src/commit.c b/src/commit.c
index eda57c5..58abd58 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -204,7 +204,7 @@ int git_commit__parse_buffer(git_commit *commit, void *data, size_t len)
 		if (commit->uninteresting)
 			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;
 	}
 
diff --git a/src/git/commit.h b/src/git/commit.h
index 1a57ba7..0ccf3c2 100644
--- a/src/git/commit.h
+++ b/src/git/commit.h
@@ -18,6 +18,9 @@ typedef struct git_commit git_commit;
 
 /**
  * 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 id identity of the commit to locate.  If the object is
  *        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)
 /**
  * Locate a reference to a commit, and try to load and parse it it from
  * 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 id identity of the commit to locate.  If the object is
  *        an annotated tag it will be peeled back to the commit.
diff --git a/src/revwalk.c b/src/revwalk.c
index c3b53a3..431007a 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -54,6 +54,7 @@ void gitrp_free(git_revpool *walk)
 	git_revpool_tableit_init(walk->commits, &it);
 
 	while ((commit = (git_commit *)git_revpool_tableit_next(&it)) != NULL) {
+		git_commit_list_clear(&commit->parents, 0);
 		free(commit);
 	}
 
diff --git a/tests/t0401-parse.c b/tests/t0401-parse.c
index 770de6a..d01f757 100644
--- a/tests/t0401-parse.c
+++ b/tests/t0401-parse.c
@@ -151,6 +151,8 @@ BEGIN_TEST(parse_buffer_test)
                     test_commits_broken[i],
                     strlen(test_commits_broken[i]))
                 );
+
+		git_commit_list_clear(&commit.parents, 0);
     }
 
     for (i = 0; i < working_commit_count; ++i) {
@@ -163,6 +165,8 @@ BEGIN_TEST(parse_buffer_test)
                     test_commits_working[i],
                     strlen(test_commits_working[i]))
                 );
+
+		git_commit_list_clear(&commit.parents, 0);
     }
 
     gitrp_free(pool);