From: Phillip Wood Date: Tue, 16 Jun 2020 15:49:33 GMT Subject: Re: [PATCH v2 05/12] fast-export: handle overridden main branch names correctly Message-ID: <8c65ab94-3b38-f8fc-c969-2d5eeff91ef1@gmail.com> In-Reply-To: <20200616131039.GG666057@coredump.intra.peff.net> Hi Peff On 16/06/2020 14:10, Jeff King wrote: > 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 Oh you're right, I completely misread the patch Thanks Phillip > (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 >