[PATCH v3 01/21] Return a copy of "master" when guessing defbranch fails

Richard Maw richard.maw at gmail.com
Mon Aug 1 23:35:33 CEST 2016


When resolving HEAD fails or doesn't resolve to a branch
it falls back to returning "master".

This was returning a pointer to a statically allocated buffer,
which is inconsistent with every other assignment to defbranch
which are dynamically allocated.

This has not been problematic because the string is not freed.

Signed-off-by: Richard Maw <richard.maw at gmail.com>
---
 cgit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cgit.c b/cgit.c
index 9427c4a..06c40ef 100644
--- a/cgit.c
+++ b/cgit.c
@@ -475,7 +475,7 @@ static char *guess_defbranch(void)
 
 	ref = resolve_ref_unsafe("HEAD", 0, sha1, NULL);
 	if (!ref || !starts_with(ref, "refs/heads/"))
-		return "master";
+		return xstrdup("master");
 	return xstrdup(ref + 11);
 }
 /* The caller must free filename and ref after calling this. */
-- 
2.9.0



More information about the CGit mailing list