Skip to content

Commit dccf6c1

Browse files
alexhenriegitster
authored andcommitted
log: fix memory leak if --graph is passed multiple times
Signed-off-by: Alex Henrie <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2b9c120 commit dccf6c1

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

graph.c

+12
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,18 @@ struct git_graph *graph_init(struct rev_info *opt)
401401
return graph;
402402
}
403403

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+
404416
static void graph_update_state(struct git_graph *graph, enum graph_state s)
405417
{
406418
graph->prev_state = graph->state;

graph.h

+5
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ void graph_set_column_colors(const char **colors, unsigned short colors_max);
139139
*/
140140
struct git_graph *graph_init(struct rev_info *opt);
141141

142+
/*
143+
* Free a struct git_graph.
144+
*/
145+
void graph_clear(struct git_graph *graph);
146+
142147
/*
143148
* Update a git_graph with a new commit.
144149
* This will cause the graph to begin outputting lines for the new commit

revision.c

+1
Original file line numberDiff line numberDiff line change
@@ -2426,6 +2426,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
24262426
} else if (!strcmp(arg, "--graph")) {
24272427
revs->topo_order = 1;
24282428
revs->rewrite_parents = 1;
2429+
graph_clear(revs->graph);
24292430
revs->graph = graph_init(revs);
24302431
} else if (!strcmp(arg, "--encode-email-headers")) {
24312432
revs->encode_email_headers = 1;

0 commit comments

Comments
 (0)