From mboxrd@z Thu Jan 1 00:00:00 1970 From: richard.maw at gmail.com (Richard Maw) Date: Mon, 1 Aug 2016 22:35:33 +0100 Subject: [PATCH v3 01/21] Return a copy of "master" when guessing defbranch fails In-Reply-To: <20160801213553.16807-1-richard.maw@gmail.com> References: <20160801213553.16807-1-richard.maw@gmail.com> Message-ID: <20160801213553.16807-2-richard.maw@gmail.com> 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 --- 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