Subject: Re: [PATCH 18/22] builtin/grep: fix leaking object context

From: Junio C Hamano <[email-masked]>
Date: Wed, 04 Sep 2024 15:36:17 -0700

Patrick Steinhardt <[email-masked]> writes:

> Even when `get_oid_with_context()` fails it may have allocated some data
> in tthe object context. But we do not release it in git-grep(1) when the

"tthe" -> "the".

> call fails, leading to a memory leak. Plug it.
>
> Signed-off-by: Patrick Steinhardt <[email-masked]>
> ---
>  builtin/grep.c                 | 1 +
>  t/t6132-pathspec-exclude.sh    | 1 +
>  t/t6135-pathspec-with-attrs.sh | 2 ++
>  3 files changed, 4 insertions(+)
>
> diff --git a/builtin/grep.c b/builtin/grep.c
> index dfc3c3e8bd2..dda4582d646 100644
> --- a/builtin/grep.c
> +++ b/builtin/grep.c
> @@ -1133,6 +1133,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
>  					 &oid, &oc)) {
>  			if (seen_dashdash)
>  				die(_("unable to resolve revision: %s"), arg);
> +			object_context_release(&oc);
>  			break;
>  		}

OK.  This is the "oh, this is not a revision argument" codepath.  It
is perfectly normal for get_oid_with_context() to fail here, and we
should make sure we clear the context variable.

Thanks.