list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: "René Scharfe" <>
To: Git Mailing List <>
Cc: Junio C Hamano <>
Subject: [PATCH] diff-lib: plug minor memory leaks in do_diff_cache()
Date: Sat, 14 Nov 2020 19:37:03 +0100	[thread overview]
Message-ID: <> (raw)

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.

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.

Signed-off-by: René Scharfe <>
 diff-lib.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/diff-lib.c b/diff-lib.c
index 082e249fc3..b73cc1859a 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -606,10 +606,12 @@ int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt)

 	repo_init_revisions(opt->repo, &revs, NULL);
 	copy_pathspec(&revs.prune_data, &opt->pathspec);
+	diff_setup_done(&revs.diffopt);
 	revs.diffopt = *opt;

 	if (diff_cache(&revs, tree_oid, NULL, 1))
+	clear_pathspec(&revs.prune_data);
 	return 0;


             reply	other threads:[~2020-11-14 18:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-14 18:37 René Scharfe [this message]
2020-11-17  0:35 ` Jeff King

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:

  List information:

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

  git send-email \ \ \ \ \
    --subject='Re: [PATCH] diff-lib: plug minor memory leaks in do_diff_cache()' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

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).