Commit 7ae5ab5696d1810eeb4583ef77145edccdb41308

Carlos Martín Nieto 2012-10-15T16:35:10

Fix leak in the tests Also introduce the slective ref trimming promised but also missed in the previous commit.

diff --git a/src/refs.c b/src/refs.c
index 9e2311b..740d99e 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -211,8 +211,6 @@ static int loose_lookup(git_reference *ref)
 	if (!updated)
 		return 0;
 
-	git_buf_rtrim(&ref_file);
-
 	if (ref->flags & GIT_REF_SYMBOLIC) {
 		git__free(ref->target.symbolic);
 		ref->target.symbolic = NULL;
@@ -222,6 +220,7 @@ static int loose_lookup(git_reference *ref)
 
 	if (git__prefixcmp((const char *)(ref_file.ptr), GIT_SYMREF) == 0) {
 		ref->flags |= GIT_REF_SYMBOLIC;
+		git_buf_rtrim(&ref_file);
 		result = loose_parse_symbolic(ref, &ref_file);
 	} else {
 		ref->flags |= GIT_REF_OID;
diff --git a/tests-clar/refs/read.c b/tests-clar/refs/read.c
index fc2d6b9..c2647e2 100644
--- a/tests-clar/refs/read.c
+++ b/tests-clar/refs/read.c
@@ -212,6 +212,7 @@ void test_refs_read__trailing(void)
 	cl_git_pass(git_reference_lookup(&test, g_repo, "refs/heads/test"));
 	cl_git_pass(git_reference_lookup(&trailing, g_repo, "refs/heads/trailing"));
 	cl_git_pass(git_oid_cmp(git_reference_oid(test), git_reference_oid(trailing)));
+	git_reference_free(trailing);
 	cl_git_pass(git_reference_lookup(&trailing, g_repo, "FETCH_HEAD"));
 
 	git_reference_free(test);