Subject: Re: [PATCH] test-tool: fix leak in delete-gpgsig command

From: Junio C Hamano <[email-masked]>
Date: Wed, 29 Oct 2025 12:35:17 -0700

Jeff King <[email-masked]> writes:

> On Tue, Oct 28, 2025 at 03:55:51PM -0700, Junio C Hamano wrote:
>
>> * tz/test-prepare-gnupghome (2024-07-03) 2 commits
>>  - t/lib-gpg: call prepare_gnupghome() in GPG2 prereq
>>  - t/lib-gpg: add prepare_gnupghome() to create GNUPGHOME dir
>> 
>>  Tests did not set up GNUPGHOME correctly, which is fixed but some
>>  flaky tests are exposed in t1016, which needs to be addressed
>>  before this topic can move forward.
>> 
>>  Will merge to 'next'.
>>  cf. <[email-masked]>
>>  cf. <[email-masked]>
>>  cf. <[email-masked]>
>>  source: <[email-masked]>
>
> I noticed jch failing CI. I think we want this on top:

Thanks.  I was just looking at these failures and thanks for beating
me to it.

> -- >8 --
> Subject: [PATCH] test-tool: fix leak in delete-gpgsig command
>
> We read the input into a strbuf, so we must free it. Without this, t1016
> complains in SANITIZE=leak mode.
>
> The bug was introduced in 7673ecd2dc (t1016-compatObjectFormat: add
> tests to verify the conversion between objects, 2023-10-01). But nobody
> seems to have noticed, probably because CI did not run these tests until
> the fix in 6cd8369ef3 (t/lib-gpg: call prepare_gnupghome() in GPG2
> prereq, 2024-07-03).
>
> Signed-off-by: Jeff King <[email-masked]>
> ---
>  t/helper/test-delete-gpgsig.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/t/helper/test-delete-gpgsig.c b/t/helper/test-delete-gpgsig.c
> index e36831af03..658c7a37f7 100644
> --- a/t/helper/test-delete-gpgsig.c
> +++ b/t/helper/test-delete-gpgsig.c
> @@ -23,8 +23,7 @@ int cmd__delete_gpgsig(int argc, const char **argv)
>  	if (!strcmp(pattern, "trailer")) {
>  		size_t payload_size = parse_signed_buffer(buf.buf, buf.len);
>  		fwrite(buf.buf, 1, payload_size, stdout);
> -		fflush(stdout);
> -		return 0;
> +		goto out;
>  	}
>  
>  	bufptr = buf.buf;
> @@ -56,7 +55,9 @@ int cmd__delete_gpgsig(int argc, const char **argv)
>  		fwrite(bufptr, 1, (eol - bufptr) + 1, stdout);
>  		bufptr = eol + 1;
>  	}
> -	fflush(stdout);
>  
> +out:
> +	fflush(stdout);
> +	strbuf_release(&buf);
>  	return 0;
>  }