Re: [PATCH 2/4] shallow: fix memory leak when registering shallow roots
- From
Jeff King <peff@peff.net>
- Date
- Nov 6, 2023, 17:21 UTC
- Message-ID
- <20231106172154.GB10414@coredump.intra.peff.net>
- In-Reply-To
- <137c150e358a8248200e0c7174a79358adb92e45.1699267422.git.ps@pks.im>
On Mon, Nov 06, 2023 at 11:45:57AM +0100, Patrick Steinhardt wrote:
Show 13 quoted lines
> --- a/shallow.c
> +++ b/shallow.c
> @@ -38,8 +38,10 @@ int register_shallow(struct repository *r, const struct object_id *oid)
>
> oidcpy(&graft->oid, oid);
> graft->nr_parent = -1;
> - if (commit && commit->object.parsed)
> + if (commit && commit->object.parsed) {
> + free_commit_list(commit->parents);
> commit->parents = NULL;
> + }
> return register_commit_graft(r, graft, 0);
> }Good catch. When I've dealt with leaks around commit_lists in the past, one gotcha is that sometimes we've saved a pointer to the list elsewhere. But in this case it looks pretty clear that the parent list just goes away. So this patch is doing the right thing.
-Peff