log: fix memory leak if --graph is passed multiple times

Signed-off-by: Alex Henrie <alexhenrie24@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Alex Henrie committed Feb 11, 2022 at 09:36 UTC dccf6c16f1cee485f05ef42ba67a9309c358a78d
3 files changed +18
graph.c
+12
@@ -401,6 +401,18 @@ struct git_graph *graph_init(struct rev_info *opt)
401 return graph;
402 }
403
404 +void graph_clear(struct git_graph *graph)
405 +{
406 + if (!graph)
407 + return;
408 +
409 + free(graph->columns);
410 + free(graph->new_columns);
411 + free(graph->mapping);
412 + free(graph->old_mapping);
413 + free(graph);
414 +}
415 +
416 static void graph_update_state(struct git_graph *graph, enum graph_state s)
417 {
418 graph->prev_state = graph->state;
graph.h
+5
@@ -139,6 +139,11 @@ void graph_set_column_colors(const char **colors, unsigned short colors_max);
139 */
140 struct git_graph *graph_init(struct rev_info *opt);
141
142 +/*
143 + * Free a struct git_graph.
144 + */
145 +void graph_clear(struct git_graph *graph);
146 +
147 /*
148 * Update a git_graph with a new commit.
149 * This will cause the graph to begin outputting lines for the new commit
revision.c
+1
@@ -2426,6 +2426,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
2426 } else if (!strcmp(arg, "--graph")) {
2427 revs->topo_order = 1;
2428 revs->rewrite_parents = 1;
2429 + graph_clear(revs->graph);
2430 revs->graph = graph_init(revs);
2431 } else if (!strcmp(arg, "--encode-email-headers")) {
2432 revs->encode_email_headers = 1;