Subject: Re: [PATCH 2/2] commit: use strbuf_release() instead of UNLEAK()

From: Junio C Hamano <[email-masked]>
Date: Wed, 16 Feb 2022 10:03:53 -0800

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

> Convert the UNLEAK() added in 0e5bba53af7 (add UNLEAK annotation for
> reducing leak false positives, 2017-09-08) to release the memory using
> strbuf_release() instead.
>
> The tests being marked as passing with
> "TEST_PASSES_SANITIZE_LEAK=true" already passed before due to the
> UNLEAK(), but now they really don't leak memory, so let's mark them as
> such.

That smells like a brave move.

Specifically, the cited commit turned an existing strbuf_release()
on &err into UNLEAK().  If that and the other strbuf (sb) were so
easily releasable, why didn't we do so back then already?

> Signed-off-by: Ævar Arnfjörð Bjarmason <[email-masked]>
> ---
>  builtin/commit.c                 | 4 ++--
>  t/t2203-add-intent.sh            | 1 +
>  t/t7011-skip-worktree-reading.sh | 1 +
>  3 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 696b3527adf..c38ae2b7656 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -1866,7 +1866,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>  
>  cleanup:
>  	strbuf_release(&author_ident);
> -	UNLEAK(err);
> -	UNLEAK(sb);
> +	strbuf_release(&err);
> +	strbuf_release(&sb);
>  	return ret;
>  }