git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git Mailing List <git@vger.kernel.org>,
	Junio C Hamano <gitster@pobox.com>,
	Derrick Stolee <stolee@gmail.com>,
	Derrick Stolee <dstolee@microsoft.com>
Subject: Re: [PATCH] commit-reach: plug minor memory leak after using is_descendant_of()
Date: Fri, 19 Jun 2020 09:31:59 -0400	[thread overview]
Message-ID: <20200619133159.GB2540897@coredump.intra.peff.net> (raw)
In-Reply-To: <ada13c16-d964-c6ee-80ac-626edbc5f52d@web.de>

On Fri, Jun 19, 2020 at 03:13:46PM +0200, René Scharfe wrote:

> ref_newer() builds a commit_list to pass a single potential ancestor to
> is_descendant_of().  The latter leaves the list intact.  Release the
> allocated memory after the call.

Looks obviously correct.

> ---
> We could allocate the commit_list on the stack, which would simplify such
> glue code quite a bit.  That would be dangerous in case is_descendant_of()
> or some other function that is handed such a list tries to consume/free()
> it.  How can we be tell a function is safe to be given a stack-allocated
> list?  Perhaps by marking its argument as const.  Or by converting all
> functions to arrays.

Yeah, if we're not worried about the performance implications of the
extra allocation, I think it's better to err on the side of safety.

I do agree that if we consistently passed an array (and length), some of
these functions would get less awkward. I tried a few years ago to
convert many of the commit_list uses to arrays, but it was a bit of a
yak shave, since often they get lists from callers, who get it from
rev_info, etc. And some of those callers _do_ like having lists, because
they want to do O(1) splicing, etc.

-Peff

  reply	other threads:[~2020-06-19 13:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-19 13:13 [PATCH] commit-reach: plug minor memory leak after using is_descendant_of() René Scharfe
2020-06-19 13:31 ` Jeff King [this message]
2020-06-19 14:07   ` Derrick Stolee

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=20200619133159.GB2540897@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    --cc=stolee@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).