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 <[email protected]>
---
 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

_______________________________________________
CGit mailing list
[email protected]
http://lists.zx2c4.com/mailman/listinfo/cgit

Reply via email to