git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/4] log: fix memory leak if --graph is passed multiple times
@ 2022-02-10 16:52 Alex Henrie
  2022-02-10 16:52 ` [PATCH v2 2/4] log: add a --no-graph option Alex Henrie
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alex Henrie @ 2022-02-10 16:52 UTC (permalink / raw)
  To: git, paulus; +Cc: Alex Henrie

Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
v2: introduce graph_clear function
---
 graph.c    | 12 ++++++++++++
 graph.h    |  5 +++++
 revision.c |  1 +
 3 files changed, 18 insertions(+)

diff --git a/graph.c b/graph.c
index e3828eb8f2..568b6e7cd4 100644
--- a/graph.c
+++ b/graph.c
@@ -401,6 +401,18 @@ struct git_graph *graph_init(struct rev_info *opt)
 	return graph;
 }
 
+void graph_clear(struct git_graph *graph)
+{
+	if (!graph)
+		return;
+
+	free(graph->columns);
+	free(graph->new_columns);
+	free(graph->mapping);
+	free(graph->old_mapping);
+	free(graph);
+}
+
 static void graph_update_state(struct git_graph *graph, enum graph_state s)
 {
 	graph->prev_state = graph->state;
diff --git a/graph.h b/graph.h
index 8313e293c7..e88632a014 100644
--- a/graph.h
+++ b/graph.h
@@ -139,6 +139,11 @@ void graph_set_column_colors(const char **colors, unsigned short colors_max);
  */
 struct git_graph *graph_init(struct rev_info *opt);
 
+/*
+ * Free a struct git_graph.
+ */
+void graph_clear(struct git_graph *graph);
+
 /*
  * Update a git_graph with a new commit.
  * This will cause the graph to begin outputting lines for the new commit
diff --git a/revision.c b/revision.c
index ad4286fbdd..816061f3d9 100644
--- a/revision.c
+++ b/revision.c
@@ -2426,6 +2426,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 	} else if (!strcmp(arg, "--graph")) {
 		revs->topo_order = 1;
 		revs->rewrite_parents = 1;
+		graph_clear(revs->graph);
 		revs->graph = graph_init(revs);
 	} else if (!strcmp(arg, "--encode-email-headers")) {
 		revs->encode_email_headers = 1;
-- 
2.32.0.2645.gc109162a1f


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-10 16:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-10 16:52 [PATCH v2 1/4] log: fix memory leak if --graph is passed multiple times Alex Henrie
2022-02-10 16:52 ` [PATCH v2 2/4] log: add a --no-graph option Alex Henrie
2022-02-10 16:52 ` [PATCH v2 3/4] log: add a log.graph config option Alex Henrie
2022-02-10 16:52 ` [PATCH v2 4/4] gitk: pass --no-graph to `git log` Alex Henrie

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 NNTP newsgroup(s).