From: Jeff King Date: Tue, 16 Jun 2020 13:10:39 GMT Subject: Re: [PATCH v2 05/12] fast-export: handle overridden main branch names correctly Message-ID: <20200616131039.GG666057@coredump.intra.peff.net> In-Reply-To: On Mon, Jun 15, 2020 at 04:05:52PM +0100, Phillip Wood wrote: > > @@ -515,14 +515,23 @@ static const char *anonymize_refname(const char *refname) > > }; > > static struct hashmap refs; > > static struct strbuf anon = STRBUF_INIT; > > + static char *main_branch; > [...] > > - if (!strcmp(refname, "refs/heads/master")) > > + if (!main_branch) > > + main_branch = git_main_branch_name(MAIN_BRANCH_FULL_NAME); > > + > > + if (!strcmp(refname, main_branch)) > > return "refs/heads/ref0"; > > This leaks main_branch if it came from git_main_branch_name() It's a static that's used over and over, so I think it's intentional to essentially memoize it for the life of the program (at which point we could free it, but don't bother to do so, letting the process exit take care of it, and trusting in leak detectors to be aware that it's still reachable, as we do for lots of other process-lifetime allocations). -Peff