All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Nicolas Le Cam <niko.lecam@gmail.com>,  git@vger.kernel.org
Subject: Re: [PATCH 2/1] revision: simplify mark_argv_for_free() callers
Date: Tue, 01 Sep 2026 11:02:27 -0700	[thread overview]
Message-ID: <xmqq8q5ksvd8.fsf@gitster.g> (raw)
In-Reply-To: <20260901063645.GA2951423@coredump.intra.peff.net> (Jeff King's message of "Tue, 1 Sep 2026 02:36:45 -0400")

Jeff King <peff@peff.net> writes:

> BTW, this is a small cleanup that I resisted putting into the earlier
> commit in order to keep it focused. But maybe worth doing on top?

I like it.  It is a tiny simplification but makes the callers easier
to read.

>
> -- >8 --
> Subject: revision: simplify mark_argv_for_free() callers
>
> You do not want to mark an argv element for freeing unless the caller
> has given us the free_removed_argv_elements flag. Originally we just
> called free() in this case, so each caller checked the flag itself. Now
> that we mark them via a helper function, we can push the check down into
> the helper. This saves a little bit of duplicated code, but also
> hopefully makes the result conceptually simpler.
>
> Every caller but one was already checking this flag. The exception is
> setup_revisions_from_strvec(), but it always sets the flag explicitly
> (since its whole purpose is managing argv memory). So even though it was
> not checking the flag, doing so is OK (it will always be set).
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
>  revision.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/revision.c b/revision.c
> index 7aee96bd8e..59d6372506 100644
> --- a/revision.c
> +++ b/revision.c
> @@ -2317,8 +2317,11 @@ static timestamp_t parse_age(const char *arg)
>   * usual const argv array, even when opt->free_removed_argv_elements is set).
>   * We cast away the const on their behalf.
>   */
> -static void mark_argv_for_free(struct rev_info *revs, const char *str)
> +static void mark_argv_for_free(const struct setup_revision_opt *opt,
> +			       struct rev_info *revs, const char *str)
>  {
> +	if (!opt || !opt->free_removed_argv_elements)
> +		return;
>  	if (!str)
>  		return;
>  	strvec_push_nodup(&revs->argv_to_free, (char *)str);
> @@ -2335,8 +2338,7 @@ static void overwrite_argv(int *argc, const char **argv,
>  	 * cases around the free() and NULL operations.
>  	 */
>  	if (*value != argv[*argc]) {
> -		if (opt && opt->free_removed_argv_elements)
> -			mark_argv_for_free(revs, argv[*argc]);
> +		mark_argv_for_free(opt, revs, argv[*argc]);
>  		argv[*argc] = *value;
>  		*value = NULL;
>  	}
> @@ -3055,8 +3057,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
>  			const char *arg = argv[i];
>  			if (strcmp(arg, "--"))
>  				continue;
> -			if (opt && opt->free_removed_argv_elements)
> -				mark_argv_for_free(revs, argv[i]);
> +			mark_argv_for_free(opt, revs, argv[i]);
>  			argv[i] = NULL;
>  			argc = i;
>  			if (argv[i + 1])
> @@ -3260,8 +3261,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
>  	}
>  
>  	if (argv) {
> -		if (opt && opt->free_removed_argv_elements)
> -			mark_argv_for_free(revs, argv[left]);
> +		mark_argv_for_free(opt, revs, argv[left]);
>  		argv[left] = NULL;
>  	}
>  
> @@ -3283,7 +3283,7 @@ void setup_revisions_from_strvec(struct strvec *argv, struct rev_info *revs,
>  	ret = setup_revisions(argv->nr, argv->v, revs, opt);
>  
>  	for (size_t i = ret; i < argv->nr; i++)
> -		mark_argv_for_free(revs, argv->v[i]);
> +		mark_argv_for_free(opt, revs, argv->v[i]);
>  	argv->nr = ret;
>  }

  reply	other threads:[~2026-09-01 18:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-30 21:55 [BUG] git stash show --src-prefix prints freed memory since 2.52.0 Nicolas Le Cam
2026-09-01  6:28 ` [PATCH] revision: hang on to "freed" argv elements Jeff King
2026-09-01  6:36   ` [PATCH 2/1] revision: simplify mark_argv_for_free() callers Jeff King
2026-09-01 18:02     ` Junio C Hamano [this message]
2026-09-01  8:51   ` [PATCH] revision: hang on to "freed" argv elements Patrick Steinhardt
2026-09-01  9:21     ` Jeff King
2026-09-01 11:08       ` Patrick Steinhardt

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=xmqq8q5ksvd8.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=niko.lecam@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.