git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Josh Steadmon <steadmon@google.com>,
	Calvin Wan <calvinwan@google.com>,
	git@vger.kernel.org
Subject: Re: [PATCH 15/22] negotiator/skipping: fix leaking commit entries
Date: Thu, 29 Aug 2024 10:41:37 +0200	[thread overview]
Message-ID: <ZtA0Oj0o3UXmSIDP@tanuki> (raw)
In-Reply-To: <fazvh3gejzofti6ii4x2fkoh66hni6lcc6axc7w4tspte4lioy@hgnvhue2pm26>

On Wed, Aug 28, 2024 at 03:19:10PM -0700, Josh Steadmon wrote:
> On 2024.08.28 20:29, Calvin Wan wrote:
> > Patrick Steinhardt <ps@pks.im> writes:
> > > When releasing the skipping negotiator we free its priority queue, but
> > > not the contained entries. Fix this to plug a memory leak.
> > > 
> > > Signed-off-by: Patrick Steinhardt <ps@pks.im>
> > > ---
> > >  negotiator/skipping.c                | 7 +++++--
> > >  t/t5552-skipping-fetch-negotiator.sh | 2 ++
> > >  2 files changed, 7 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/negotiator/skipping.c b/negotiator/skipping.c
> > > index f65d47858b4..b738fe4faef 100644
> > > --- a/negotiator/skipping.c
> > > +++ b/negotiator/skipping.c
> > > @@ -247,8 +247,11 @@ static int ack(struct fetch_negotiator *n, struct commit *c)
> > >  
> > >  static void release(struct fetch_negotiator *n)
> > >  {
> > > -	clear_prio_queue(&((struct data *)n->data)->rev_list);
> > > -	FREE_AND_NULL(n->data);
> > > +	struct data *data = n->data;
> > > +	for (int i = 0; i < data->rev_list.nr; i++)
> > > +		free(data->rev_list.array[i].data);
> > > +	clear_prio_queue(&data->rev_list);
> > > +	FREE_AND_NULL(data);
> > >  }
> > >  
> > 
> > It seems unintuitive that clear_prio_queue() doesn't also free the data
> > underneath and that a caller would have to know to free that as well to
> > avoid leaking memory. Would it make more sense to add this change to
> > clear_prio_queue() instead? Patch 14 has that pattern already.
> 
> I'm assuming the reasoning is that clear_prio_queue() can't know if its
> items need more complicated cleanup of their own, so if the caller
> (potentially) needs to clean up items individually anyway, the caller
> can also free them at the same time?

Yeah, that's mostly the reason. We have e.g. `string_list_clear_func()`
that works around this issue by making the caller provide the cleanup
function, and we could use the same pattern here. But it seems as if
most of the callers of `clear_prio_queue()` don't need this because they
already drain the queue during normal operations anyway.

With patch 14 you probably refer to `clear_shallow_info()`? We're not
using a priority queue there, so it is not quite related to the prio
queue we have here. So I'm inclined to leave this as-is, and if we ever
see that we have more callsites that want to clean up the prio queue and
its contents we can introduce `prio_queue_clear_func()`. Does that work
for you?

> > Thanks again for the cleanups -- I'm tempted to take a stab at some of
> > the other memory leaks you mentioned during our biweekly hackathon. All
> > of the other patches look reasonable to me.

I'd certainly be happy to shed some of the load here. If you do, please
give me a quick ping so that we don't duplicate any work by accident.

> The series also looks good to me, thanks!
> 
> Reviewed-by: Josh Steadmon <steadmon@google.com>

Thanks!

Patrick

  reply	other threads:[~2024-08-29  8:41 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-26  7:21 [PATCH 00/22] Memory leak fixes (pt.6) Patrick Steinhardt
2024-08-26  7:21 ` [PATCH 01/22] t/test-lib: allow skipping leak checks for passing tests Patrick Steinhardt
2024-08-27 22:38   ` Junio C Hamano
2024-08-29 14:15   ` Toon claes
2024-08-30  9:00     ` Patrick Steinhardt
2024-08-26  7:21 ` [PATCH 02/22] fetch-pack: fix memory leaks on fetch negotiation Patrick Steinhardt
2024-08-26  7:21 ` [PATCH 03/22] send-pack: fix leaking common object IDs Patrick Steinhardt
2024-08-26  7:21 ` [PATCH 04/22] builtin/push: fix leaking refspec query result Patrick Steinhardt
2024-08-30 21:59   ` Junio C Hamano
2024-09-02  9:27     ` Patrick Steinhardt
2024-08-26  7:21 ` [PATCH 05/22] upload-pack: fix leaking child process data on reachability checks Patrick Steinhardt
2024-08-30 22:30   ` Junio C Hamano
2024-08-26  7:21 ` [PATCH 06/22] submodule: fix leaking fetch task data Patrick Steinhardt
2024-08-26  7:21 ` [PATCH 07/22] builtin/submodule--helper: fix leaking refs on push-check Patrick Steinhardt
2024-08-26  7:21 ` [PATCH 08/22] remote: fix leaking tracking refs Patrick Steinhardt
2024-09-04 21:50   ` Junio C Hamano
2024-08-26  7:21 ` [PATCH 09/22] remote: fix leak in reachability check of a remote-tracking ref Patrick Steinhardt
2024-08-26  7:22 ` [PATCH 10/22] send-pack: fix leaking push cert nonce Patrick Steinhardt
2024-09-04 22:08   ` Junio C Hamano
2024-08-26  7:22 ` [PATCH 11/22] gpg-interface: fix misdesigned signing key interfaces Patrick Steinhardt
2024-09-04 22:09   ` Junio C Hamano
2024-08-26  7:22 ` [PATCH 12/22] object: clear grafts when clearing parsed object pool Patrick Steinhardt
2024-08-26  7:22 ` [PATCH 13/22] shallow: free grafts when unregistering them Patrick Steinhardt
2024-08-26  7:22 ` [PATCH 14/22] shallow: fix leaking members of `struct shallow_info` Patrick Steinhardt
2024-08-29 14:16   ` Toon claes
2024-08-29 16:07     ` Junio C Hamano
2024-08-30  9:00       ` Patrick Steinhardt
2024-08-26  7:22 ` [PATCH 15/22] negotiator/skipping: fix leaking commit entries Patrick Steinhardt
2024-08-28 20:29   ` Calvin Wan
2024-08-28 22:19     ` Josh Steadmon
2024-08-29  8:41       ` Patrick Steinhardt [this message]
2024-08-29 17:29         ` Calvin Wan
2024-08-26  7:22 ` [PATCH 16/22] builtin/repack: fix leaking line buffer when packing promisors Patrick Steinhardt
2024-09-04 22:27   ` Junio C Hamano
2024-08-26  7:22 ` [PATCH 17/22] builtin/pack-objects: plug leaking list of keep-packs Patrick Steinhardt
2024-08-26  7:22 ` [PATCH 18/22] builtin/grep: fix leaking object context Patrick Steinhardt
2024-09-04 22:36   ` Junio C Hamano
2024-08-26  7:22 ` [PATCH 19/22] builtin/fmt-merge-msg: fix leaking buffers Patrick Steinhardt
2024-08-26  7:22 ` [PATCH 20/22] match-trees: fix leaking prefixes in `shift_tree()` Patrick Steinhardt
2024-09-04 22:42   ` Junio C Hamano
2024-08-26  7:22 ` [PATCH 21/22] merge-ort: fix two leaks when handling directory rename modifications Patrick Steinhardt
2024-09-04 22:56   ` Junio C Hamano
2024-09-05  2:01     ` Elijah Newren
2024-08-26  7:22 ` [PATCH 22/22] builtin/repack: fix leaking keep-pack list Patrick Steinhardt
2024-09-04 23:01 ` [PATCH 00/22] Memory leak fixes (pt.6) Junio C Hamano
2024-09-05 10:08 ` [PATCH v2 " Patrick Steinhardt
2024-09-05 10:08   ` [PATCH v2 01/22] t/test-lib: allow skipping leak checks for passing tests Patrick Steinhardt
2024-09-05 10:08   ` [PATCH v2 02/22] fetch-pack: fix memory leaks on fetch negotiation Patrick Steinhardt
2024-09-05 10:08   ` [PATCH v2 03/22] send-pack: fix leaking common object IDs Patrick Steinhardt
2024-09-05 10:08   ` [PATCH v2 04/22] builtin/push: fix leaking refspec query result Patrick Steinhardt
2024-09-05 10:08   ` [PATCH v2 05/22] upload-pack: fix leaking child process data on reachability checks Patrick Steinhardt
2024-09-05 10:08   ` [PATCH v2 06/22] submodule: fix leaking fetch task data Patrick Steinhardt
2024-09-05 10:08   ` [PATCH v2 07/22] builtin/submodule--helper: fix leaking refs on push-check Patrick Steinhardt
2024-09-05 10:08   ` [PATCH v2 08/22] remote: fix leaking tracking refs Patrick Steinhardt
2024-09-05 10:09   ` [PATCH v2 09/22] remote: fix leak in reachability check of a remote-tracking ref Patrick Steinhardt
2024-09-05 10:09   ` [PATCH v2 10/22] send-pack: fix leaking push cert nonce Patrick Steinhardt
2024-09-05 10:09   ` [PATCH v2 11/22] gpg-interface: fix misdesigned signing key interfaces Patrick Steinhardt
2024-09-05 10:09   ` [PATCH v2 12/22] object: clear grafts when clearing parsed object pool Patrick Steinhardt
2024-09-05 10:09   ` [PATCH v2 13/22] shallow: free grafts when unregistering them Patrick Steinhardt
2024-09-05 10:09   ` [PATCH v2 14/22] shallow: fix leaking members of `struct shallow_info` Patrick Steinhardt
2024-09-05 10:09   ` [PATCH v2 15/22] negotiator/skipping: fix leaking commit entries Patrick Steinhardt
2024-09-05 10:09   ` [PATCH v2 16/22] builtin/repack: fix leaking line buffer when packing promisors Patrick Steinhardt
2024-09-05 10:09   ` [PATCH v2 17/22] builtin/pack-objects: plug leaking list of keep-packs Patrick Steinhardt
2024-09-05 10:09   ` [PATCH v2 18/22] builtin/grep: fix leaking object context Patrick Steinhardt
2024-09-05 10:09   ` [PATCH v2 19/22] builtin/fmt-merge-msg: fix leaking buffers Patrick Steinhardt
2024-09-05 10:09   ` [PATCH v2 20/22] match-trees: fix leaking prefixes in `shift_tree()` Patrick Steinhardt
2024-09-05 10:09   ` [PATCH v2 21/22] merge-ort: fix two leaks when handling directory rename modifications Patrick Steinhardt
2024-09-05 10:09   ` [PATCH v2 22/22] builtin/repack: fix leaking keep-pack list Patrick Steinhardt
2024-09-08 21:39   ` [PATCH v2 00/22] Memory leak fixes (pt.6) Junio C Hamano
2024-09-12 20:29   ` 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=ZtA0Oj0o3UXmSIDP@tanuki \
    --to=ps@pks.im \
    --cc=calvinwan@google.com \
    --cc=git@vger.kernel.org \
    --cc=steadmon@google.com \
    /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).