git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Martin Ågren" <martin.agren@gmail.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>
Subject: Re: [PATCH v3 1/2] builtin/merge-base: free commit lists
Date: Wed, 08 Nov 2017 11:40:17 +0900	[thread overview]
Message-ID: <xmqqzi7xlcha.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <a5f5a259f4cbe3661eb1960e83e9bcce5080b580.1510083859.git.martin.agren@gmail.com> ("Martin Ågren"'s message of "Tue, 7 Nov 2017 21:39:44 +0100")

Martin Ågren <martin.agren@gmail.com> writes:

> In several functions, we iterate through a commit list by assigning
> `result = result->next`. As a consequence, we lose the original pointer
> and eventually leak the list.
>
> Rewrite the loops so that we keep the original pointers, then call
> `free_commit_list()`. Various alternatives were considered:

So, the reader expects to see a list of alternatives that we
considered but did not use in this solution to follow.

>
> 1) Use `UNLEAK(result)` before the loop. Simple change, but not very
> pretty. These would definitely be new lows among our usages of UNLEAK.

I am not sure if I agree with the judgment, but we did reject it, so
describing it as a candidate is good.

> 2) Use `pop_commit()` when looping. Slightly less simple change, but it
> feels slightly preferable to first display the list, then free it.

OK.

> 3) As in this patch, but with `UNLEAK()` instead of freeing. We'd still
> go through all the trouble of refactoring the loop, and because it's not
> super-obvious that we're about to exit, let's just free the lists -- it
> probably doesn't affect the runtime much.

That does include what we did, too.  A rejected alternative is only
the first 3/4 of what this says.

    3) As in this patch, but with `UNLEAK()` instead of freeing. We'd
       still go through all the trouble of refactoring the loop, and the
       use of UNLEAK() is left questionable because it's not very obvious
       that we're about to exit.

and then you can begin a separate paragraph, after the above lists,
e.g.

    Let's just free the lists -- it probably doesn't affect the
    runtime much.

> In `handle_independent()` we can drop `result` while we're here and
> reuse the `revs`-variable instead. That matches several other users of
> `reduce_heads()`. The memory-leak that this hides will be addressed in
> the next commit.

The patch text looks agreeable.

Thanks.

  reply	other threads:[~2017-11-08  2:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-01  9:03 [PATCH] reduce_heads: fix memory leaks Martin Ågren
2017-11-02  3:11 ` Junio C Hamano
2017-11-02 10:45   ` Martin Ågren
2017-11-05 20:26     ` [PATCH v2 0/2] " Martin Ågren
2017-11-05 20:26       ` [PATCH v2 1/2] builtin/merge-base: UNLEAK commit lists Martin Ågren
2017-11-06  1:03         ` Junio C Hamano
2017-11-06 11:05         ` Jeff King
2017-11-07 20:39           ` [PATCH v3 1/2] builtin/merge-base: free " Martin Ågren
2017-11-08  2:40             ` Junio C Hamano [this message]
2017-11-07 20:39           ` [PATCH v3 2/2] reduce_heads: fix memory leaks Martin Ågren
2017-11-05 20:26       ` [PATCH v2 " Martin Ågren
2017-11-06  1:12       ` [PATCH v2 0/2] " 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

  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=xmqqzi7xlcha.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=martin.agren@gmail.com \
    --cc=peff@peff.net \
    /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).