From: Jeff King Date: Mon, 12 Jun 2023 03:59:48 GMT Subject: Re: [PATCH 09/11] branch: fix a leak in setup_tracking Message-ID: <20230612035948.GI306352@coredump.intra.peff.net> In-Reply-To: <471dcc04-d60c-b745-15f0-05fe4e93ff11@gmail.com> On Sun, Jun 11, 2023 at 08:50:36PM +0200, Rubén Justo wrote: > The commit d3115660b4 (branch: add flags and config to inherit tracking, > 2021-12-20) replaced in "struct tracking", the member "char *src" by a > new "struct string_list *srcs". > > This caused a modification in find_tracked_branch(). The string > returned by remote_find_tracking(), previously assigned to "src", is now > added to the string_list "srcs". > > That string_list is initialized with STRING_LIST_INIT_DUP, which means > that what is added is not the given string, but a duplicate. Therefore, > the string returned by remote_find_tracking() is leaked. Your fix makes sense. I had to stare at the existing code for a long time to make sure the _other_ side of the switch wasn't leaking, but it works by falling through "case 2" into "default", which frees tracking->spec.src. So this should plug the leak completely. -Peff