Subject: Re: PATCH] bisect--helper: plug strvec leak in bisect_start()

From: Junio C Hamano <[email-masked]>
Date: Wed, 05 Oct 2022 12:44:54 -0700

Ævar Arnfjörð Bjarmason <[email-masked]> writes:

> But I don't get it in this case, why not just:
> 	
> 	diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c
> 	index 4e97817fba5..f9645a9d0df 100644
> 	--- a/builtin/bisect--helper.c
> 	+++ b/builtin/bisect--helper.c
> 	@@ -763,11 +763,9 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, const char **a
> 	 		strbuf_read_file(&start_head, git_path_bisect_start(), 0);
> 	 		strbuf_trim(&start_head);
> 	 		if (!no_checkout) {
> 	-			struct strvec argv = STRVEC_INIT;
> 	+			const char *argv[] = { "checkout", start_head.buf, "--", NULL };
> 	 
> 	-			strvec_pushl(&argv, "checkout", start_head.buf,
> 	-				     "--", NULL);
> 	-			if (run_command_v_opt(argv.v, RUN_GIT_CMD)) {
> 	+			if (run_command_v_opt(argv, RUN_GIT_CMD)) {
> 	 				res = error(_("checking out '%s' failed."
> 	 						 " Try 'git bisect start "
> 	 						 "<valid-branch>'."),
>
> The common pattern for run_command_v_opt() callers that don't need a
> dynamic list is exactly that.

I think you answered it yourself.  start_head.buf is not known at
compilation time, and there may be some superstition (it may not be
a mere superstition, but conservatism) about older compiler not
grokking it.