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
Subject: Re: [PATCH v2 1/2] builtin/merge-base: UNLEAK commit lists
Date: Mon, 06 Nov 2017 10:03:47 +0900	[thread overview]
Message-ID: <xmqqa800kyks.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <b06f593d3f8b0ad53754eeb394f77e7c3ee916bd.1509908607.git.martin.agren@gmail.com> ("Martin Ågren"'s message of "Sun, 5 Nov 2017 21:26:30 +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.
>
> These are immediate helpers to `cmd_merge_base()` which is just about to
> return, so we can use UNLEAK. For example, we could `UNLEAK(result)`
> before we start iterating. That would be a one-liner change per
> function. Instead, leave the lists alone and iterate using a dedicated
> pointer. Then UNLEAK immediately before returning.

Hmm, I cannot shake this feeling that this goes somewhat opposite to
the spirit of UNLEAK(), which I view as "It is too cumbersome and
makes the resulting code ugly if we try to make everything properly
freed, so mark what we know we will leak upfront".  The result of
this patch feels more like "Even though we took pains to restructure
the code so that we could call free_commit_list() to properly free
things, we use UNLEAK() and do not actually bother to free."

Havin said that, I do not think the resulting code has become uglier
or the conversion process (both writing and reviewing) were too
cumbersome for this particular case, and marking where we could call
free_commit_list() with UNLEAK() like this patch does may make
sense.  If somebody someday wants to call some of these helpers in
other contexts repeatedly, they may have an easier time.

  reply	other threads:[~2017-11-06  1:03 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 [this message]
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
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=xmqqa800kyks.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=martin.agren@gmail.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.
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).