git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Mike Hommey <mh@glandium.org>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] packfile: free packed_git memory when closing object store
Date: Mon, 26 Aug 2019 11:06:29 -0700	[thread overview]
Message-ID: <xmqqftlnhkd6.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20190826024508.8444-1-mh@glandium.org> (Mike Hommey's message of "Mon, 26 Aug 2019 11:45:08 +0900")

Mike Hommey <mh@glandium.org> writes:

> Signed-off-by: Mike Hommey <mh@glandium.org>
> ---
>  packfile.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> Note, I'm not sure this is the right place to do it.

I do not think this patch is complete, given that o->packed_git
still has a non-NULL pointer.  IIRC, close_pack() was written for
the explicit purpose of releasing resources while allowing us to
reopen with open_packed_git() on it, so with the current
arrangement, after releasing the resources held for this object
store and doing something else, you should be able to come back to
this object store and work in it again---this patch makes it harder
if not impossible to do so.

I _think_ the patch is OK if you assigned NULL to o->packed_git,
after making sure that the intention of all the callers of
close_object_store() is to declare that this object store will not
be accessed any longer during the lifetime of the process, and write
it down as the contract between the callers and this function in a
comment perhaps in packfile.h where the function is declared.

Thanks.

> diff --git a/packfile.c b/packfile.c
> index fc43a6c52c..b0cb84adda 100644
> --- a/packfile.c
> +++ b/packfile.c
> @@ -339,13 +339,16 @@ void close_pack(struct packed_git *p)
>  
>  void close_object_store(struct raw_object_store *o)
>  {
> -	struct packed_git *p;
> +	struct packed_git *p = o->packed_git;
>  
> -	for (p = o->packed_git; p; p = p->next)
> +	while (p) {
> +		struct packed_git *current = p;
>  		if (p->do_not_close)
>  			BUG("want to close pack marked 'do-not-close'");
> -		else
> -			close_pack(p);
> +		close_pack(p);
> +		p = p->next;
> +		free(current);
> +	}
>  
>  	if (o->multi_pack_index) {
>  		close_midx(o->multi_pack_index);

  reply	other threads:[~2019-08-26 18:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-26  2:45 [PATCH] packfile: free packed_git memory when closing object store Mike Hommey
2019-08-26 18:06 ` Junio C Hamano [this message]
2019-08-27  0:25   ` Mike Hommey

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqqftlnhkd6.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=mh@glandium.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).