Skip to content

Commit 0bfb48e

Browse files
Martin Ågrengitster
authored andcommitted
builtin/commit-graph.c: UNLEAK variables
`graph_verify()`, `graph_read()` and `graph_write()` do the hard work of `cmd_commit_graph()`. As soon as these return, so does `cmd_commit_graph()`. `strbuf_getline()` may allocate memory in the strbuf, yet return EOF. We need to release the strbuf or UNLEAK it. Go for the latter since we are close to returning from `graph_write()`. `graph_write()` also fails to free the strings in the string list. They have been added to the list with `strdup_strings` set to 0. We could flip `strdup_strings` before clearing the list, which is our usual hack in situations like this. But since we are about to exit, let's just UNLEAK the whole string list instead. UNLEAK `graph` in `graph_verify`. While at it, and for consistency, UNLEAK in `graph_read()` as well, and remove an unnecessary UNLEAK just before dying. Signed-off-by: Martin Ågren <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f4dbdfc commit 0bfb48e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

builtin/commit-graph.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static int graph_verify(int argc, const char **argv)
6464
if (!graph)
6565
return 0;
6666

67+
UNLEAK(graph);
6768
return verify_commit_graph(the_repository, graph);
6869
}
6970

@@ -89,10 +90,8 @@ static int graph_read(int argc, const char **argv)
8990
graph_name = get_commit_graph_filename(opts.obj_dir);
9091
graph = load_commit_graph_one(graph_name);
9192

92-
if (!graph) {
93-
UNLEAK(graph_name);
93+
if (!graph)
9494
die("graph file %s does not exist", graph_name);
95-
}
9695

9796
FREE_AND_NULL(graph_name);
9897

@@ -115,7 +114,7 @@ static int graph_read(int argc, const char **argv)
115114
printf(" large_edges");
116115
printf("\n");
117116

118-
free_commit_graph(graph);
117+
UNLEAK(graph);
119118

120119
return 0;
121120
}
@@ -166,6 +165,8 @@ static int graph_write(int argc, const char **argv)
166165
pack_indexes = &lines;
167166
if (opts.stdin_commits)
168167
commit_hex = &lines;
168+
169+
UNLEAK(buf);
169170
}
170171

171172
write_commit_graph(opts.obj_dir,
@@ -174,7 +175,7 @@ static int graph_write(int argc, const char **argv)
174175
opts.append,
175176
1);
176177

177-
string_list_clear(&lines, 0);
178+
UNLEAK(lines);
178179
return 0;
179180
}
180181

0 commit comments

Comments
 (0)