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>
Subject: Re: [PATCH] diff-lib: plug minor memory leaks in do_diff_cache()
Date: Mon, 16 Nov 2020 19:35:11 -0500 [thread overview]
Message-ID: <20201117003511.GC13516@coredump.intra.peff.net> (raw)
In-Reply-To: <80fb4a2a-992f-7d3b-9413-5059da3a8f01@web.de>
On Sat, Nov 14, 2020 at 07:37:03PM +0100, René Scharfe wrote:
> do_diff_cache() builds a struct rev_info to hand to diff_cache() from
> scratch by initializing it using repo_init_revisions() and then
> replacing its diffopt and prune_data members.
>
> The diffopt member is initialized to a heap-allocated list of options,
> though. Release it using diff_setup_done() before overwriting it.
Makes sense. This whole "rewrite the options as a heap-allocated list"
thing is pretty gross, but is probably the least-bad solution to the
problem. I wondered if there might be other unpaired diff_setup() /
diff_setup_done() calls. Curiously, there are more of the latter:
$ git grep 'diff_setup(' | wc -l
22
$ git grep 'diff_setup_done(' | wc -l
35
I think because repo_init_revisions() makes an implicit call to
diff_setup().
> The initial value of the prune_data member doesn't need to be released,
> but the copy created using copy_pathspec() does. Clear it after use.
I suspect there are more elements of rev_info that could be allocated
(e.g., in a traversal without "--objects", I think trees and blobs are
left sitting in the pending array). It's a prime candidate for UNLEAK()
in most cases where we do a single traversal and then exit the program.
But for sub-functions like this, we perhaps should bite the bullet and
just make a rev_info_clear() function that can be used everywhere.
(I'm not opposed to your patch here in the meantime, though).
-Peff
prev parent reply other threads:[~2020-11-17 0:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-14 18:37 [PATCH] diff-lib: plug minor memory leaks in do_diff_cache() René Scharfe
2020-11-17 0:35 ` Jeff King [this message]
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=20201117003511.GC13516@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=l.s.r@web.de \
/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).