Re: [PATCH 09/11] branch: fix a leak in setup_tracking
From: Jeff King <hidden>
Date: 2023-06-12 03:59:55
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