Re: [PATCH 6/9] repository: free main reference database
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Jun 12, 2026, 09:20 UTC
- Message-ID
- <CAOLa=ZRUF61cp5JqXKwpNLf1BO3bhMFAT5Ph_-yvz1D9-qUSzw@mail.gmail.com>
- In-Reply-To
- <20260610-b4-pks-refs-avoid-chdir-notify-reparent-v1-6-56c864b01c43@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 7 quoted lines
> While we release worktree and submodule reference databases when > clearing a repository, we don't ever release the main reference > database. This memory leak went unnoticed because its pointer is > kept alive by the "chdir_notify" subsystem. > > Fix the memory leak. >
Funny, cause long ago I looked into this and thought I was clearly missing something and eventually forgot about it. Good to know that I was correct :)
Show 24 quoted lines
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> repository.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/repository.c b/repository.c
> index 187dd471c4..e2b5c6712b 100644
> --- a/repository.c
> +++ b/repository.c
> @@ -421,6 +421,11 @@ void repo_clear(struct repository *repo)
> FREE_AND_NULL(repo->remote_state);
> }
>
> + if (repo->refs_private) {
> + ref_store_release(repo->refs_private);
> + FREE_AND_NULL(repo->refs_private);
> + }
> +
> strmap_for_each_entry(&repo->submodule_ref_stores, &iter, e)
> ref_store_release(e->value);
> strmap_clear(&repo->submodule_ref_stores, 1);
>
> --
> 2.54.0.1189.g8c84645362.dirty