git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/4] shallow: fix memory leak when registering shallow roots
Date: Mon, 6 Nov 2023 12:21:54 -0500	[thread overview]
Message-ID: <20231106172154.GB10414@coredump.intra.peff.net> (raw)
In-Reply-To: <137c150e358a8248200e0c7174a79358adb92e45.1699267422.git.ps@pks.im>

On Mon, Nov 06, 2023 at 11:45:57AM +0100, Patrick Steinhardt wrote:

> --- 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

  reply	other threads:[~2023-11-06 17:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-06 10:45 [PATCH 0/4] Memory leak fixes Patrick Steinhardt
2023-11-06 10:45 ` [PATCH 1/4] test-bloom: stop setting up Git directory twice Patrick Steinhardt
2023-11-06 17:20   ` Jeff King
2023-11-06 10:45 ` [PATCH 2/4] shallow: fix memory leak when registering shallow roots Patrick Steinhardt
2023-11-06 17:21   ` Jeff King [this message]
2023-11-06 10:46 ` [PATCH 3/4] setup: refactor `upgrade_repository_format()` to have common exit Patrick Steinhardt
2023-11-06 10:46 ` [PATCH 4/4] setup: fix leaking repository format Patrick Steinhardt
2023-11-06 17:32 ` [PATCH 0/4] Memory leak fixes Jeff King
2023-11-07  2:20   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231106172154.GB10414@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).