Re: [PATCH] merge: fix leak with merge.defaultToUpstream
- From
Jeff King <peff@peff.net>
- Date
- Jul 28, 2026, 15:19 UTC
- Message-ID
- <20260728151959.GC41931@coredump.intra.peff.net>
- In-Reply-To
- <20260728-toon-fix-merge-leak-v1-1-d6bd161a3acf@iotcl.com>
On Tue, Jul 28, 2026 at 03:00:04PM +0200, Toon Claes wrote:
Show 7 quoted lines
> 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.
Show 9 quoted lines
> @@ -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.
-Peff