git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Mike Hommey <mh@glandium.org>
To: git@vger.kernel.org
Cc: gitster@pobox.com
Subject: [PATCH 2/2] revision: free topo_walk_info before creating a new one in init_topo_walk
Date: Fri, 22 Nov 2019 17:37:04 +0900	[thread overview]
Message-ID: <20191122083704.29267-2-mh@glandium.org> (raw)
In-Reply-To: <20191122083704.29267-1-mh@glandium.org>

init_topo_walk doesn't reuse an existing topo_walk_info, and currently
leaks the one that might exist on the current rev_info if it was already
used for a topo walk beforehand.

Signed-off-by: Mike Hommey <mh@glandium.org>
---
 revision.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)


The FREE_AND_NULL() -> xmalloc dance could be avoided, but I figured the
function ought to be reused in the future to clear the rev_info. I was
thinking to add a call in reset_revision_walk instead, but
reset_revision_walk doesn't take an argument at all currently.


diff --git a/revision.c b/revision.c
index 765a56ae33..7e23c5ed08 100644
--- a/revision.c
+++ b/revision.c
@@ -3211,10 +3211,26 @@ static void compute_indegrees_to_depth(struct rev_info *revs,
 		indegree_walk_step(revs);
 }
 
+static void reset_topo_walk(struct rev_info *revs)
+{
+	struct topo_walk_info *info = revs->topo_walk_info;
+
+	clear_prio_queue(&info->explore_queue);
+	clear_prio_queue(&info->indegree_queue);
+	clear_prio_queue(&info->topo_queue);
+	clear_indegree_slab(&info->indegree);
+	clear_author_date_slab(&info->author_date);
+
+	FREE_AND_NULL(revs->topo_walk_info);
+}
+
 static void init_topo_walk(struct rev_info *revs)
 {
 	struct topo_walk_info *info;
 	struct commit_list *list;
+	if (revs->topo_walk_info)
+		reset_topo_walk(revs);
+
 	revs->topo_walk_info = xmalloc(sizeof(struct topo_walk_info));
 	info = revs->topo_walk_info;
 	memset(info, 0, sizeof(struct topo_walk_info));
-- 
2.24.0.dirty


  reply	other threads:[~2019-11-22  8:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-22  8:37 [PATCH 1/2] revision: clear the topo-walk flags in reset_revision_walk Mike Hommey
2019-11-22  8:37 ` Mike Hommey [this message]
2019-11-27 14:25   ` [PATCH 2/2] revision: free topo_walk_info before creating a new one in init_topo_walk Derrick Stolee
2019-12-01 16:22     ` Junio C Hamano
2019-12-04 18:55       ` Derrick Stolee
2019-12-04 19:47         ` Junio C Hamano
2019-11-27 14:22 ` [PATCH 1/2] revision: clear the topo-walk flags in reset_revision_walk 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=20191122083704.29267-2-mh@glandium.org \
    --to=mh@glandium.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).