git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] revision: free topo_walk_info before creating a new one in init_topo_walk

From
Mike Hommey <mh@glandium.org>
Date
Nov 22, 2019, 08:37 UTC
Message-ID
<20191122083704.29267-2-mh@glandium.org>
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
Previous: Mike HommeyNext: Derrick Stolee
Message 2 of 7 in “revision: clear the topo-walk flags in reset_revision_walk”
  1. 1/2 revision: clear the topo-walk flags in reset_revision_walkMike Hommey, Nov 22, 2019
  2. 2/2 revision: free topo_walk_info before creating a new one in init_topo_walkMike Hommey, Nov 22, 2019
  3. Derrick StoleeNov 27, 2019
  4. Junio C HamanoDec 1, 2019
  5. Derrick StoleeDec 4, 2019
  6. Junio C HamanoDec 4, 2019
  7. Derrick StoleeNov 27, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.