Re: [PATCH v2 05/12] fast-export: handle overridden main branch names correctly
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jun 18, 2020, 10:08 UTC
- Message-ID
- <nycvar.QRO.7.76.6.2006181208180.54@tvgsbejvaqbjf.bet>
- In-Reply-To
- <20200616131039.GG666057@coredump.intra.peff.net>
Hi Peff,
On Tue, 16 Jun 2020, Jeff King wrote:
Show 22 quoted lines
> 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).
That is indeed the intention, and I will edit the commit message accordingly.
Thanks, Dscho