git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] rebase: use child_process_clear() to clean
Date: Fri, 22 Mar 2024 10:21:23 -0700	[thread overview]
Message-ID: <xmqqedc218to.fsf@gitster.g> (raw)
In-Reply-To: <20240322103502.GA2045297@coredump.intra.peff.net> (Jeff King's message of "Fri, 22 Mar 2024 06:35:02 -0400")

Jeff King <peff@peff.net> writes:

> In the run_am() function, we set up a child_process struct to run
> "git-am", allocating memory for its args and env strvecs. These are
> normally cleaned up when we call run_command(). But if we encounter
> certain errors, we exit the function early and try to clean up ourselves
> by clearing the am.args field. This leaks the "env" strvec.
>
> We should use child_process_clear() instead, which covers both. And more
> importantly, it future proofs us against the struct ever growing more
> allocated fields.

When 21853626 (built-in rebase: call `git am` directly, 2019-01-18)
started using run_command() API to drive "am", there already was
child_process API and child_process_clear() did clear both .args and
.env_array members but we used argv_array_clear() only to clear
am.args, leaking am.env_array.

> These are unlikely errors to happen in practice, so they don't actually
> trigger the leak sanitizer in the tests. But we can add a new test which
> does exercise one of the paths (and fails SANITIZE=leak without this
> patch).
> ...
> Not sure if the test is overkill. It really does nothing useful in a
> non-leak-checking build.

I wonder what are in .env array at this point, though, but that is
mere curiosity and not a problem with this patch.

Thanks.  Will queue.


> diff --git a/t/t3438-rebase-broken-files.sh b/t/t3438-rebase-broken-files.sh
> index c614c4f2e4..821f08e5af 100755
> --- a/t/t3438-rebase-broken-files.sh
> +++ b/t/t3438-rebase-broken-files.sh
> @@ -58,4 +58,13 @@ test_expect_success 'unknown key in author-script' '
>  	check_resolve_fails
>  '
>  
> +test_expect_success POSIXPERM,SANITY 'unwritable rebased-patches does not leak' '
> +	>.git/rebased-patches &&
> +	chmod a-w .git/rebased-patches &&
> +
> +	git checkout -b side HEAD^ &&
> +	test_commit unrelated &&
> +	test_must_fail git rebase --apply --onto tmp HEAD^
> +'
> +
>  test_done

  reply	other threads:[~2024-03-22 17:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-22 10:35 [PATCH] rebase: use child_process_clear() to clean Jeff King
2024-03-22 17:21 ` Junio C Hamano [this message]
2024-03-22 23:36   ` Jeff King
2024-03-25 18:44     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqedc218to.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).