Re: [PATCH] merge: fix leak with merge.defaultToUpstream
Jeff King <peff@peff.net> writes:
Show 27 quoted lines
> On Tue, Jul 28, 2026 at 03:00:04PM +0200, Toon Claes wrote:
>
>> The leak has been present since 93e535a5b7 (merge: merge with the
>> default upstream branch without argument, 2011-03-24). Although the leak
>> sanitizer was enabled for tests in fc1ddf42af (t: remove
>> TEST_PASSES_SANITIZE_LEAK annotations, 2024-11-21), it went unnoticed
>> because no test calls `git merge` without arguments, exercising the
>> default-to-upstream path. Add such a test in t7600, which fails under
>> the leak sanitizer without this fix.
>
> Wow, I'm surprised we didn't cover this case in the test suite.
> Increasing coverage is good.
>
>> @@ -1517,8 +1517,10 @@ int cmd_merge(int argc,
>> option_commit = 1;
>>
>> if (!argc) {
>> - if (default_to_upstream)
>> + if (default_to_upstream) {
>> argc = setup_with_upstream(&argv);
>> + argv_to_free = argv;
>> + }
>
> The fix looks correct to me. This whole argv-juggling is pretty gross
> (especially the part below which overwrites argv[0]!). I suspect using a
> separate strvec to hold the heads would be cleaner, but it is probably
> not worth anybody's time to micro-polish this.Thanks for heading off my OCD before it showed ;-).
And of course, thanks Toon for noticing and fixing.
Will queue.