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 <martin.agren@gmail.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin Ågren committed Oct 3, 2018 at 10:12 UTC 0bfb48e67230393632b9b07d8ffceae94398e5b8
1 file changed +6 -5
builtin/commit-graph.c
+6 -5
@@ -64,6 +64,7 @@ static int graph_verify(int argc, const char **argv)
64 if (!graph)
65 return 0;
66
67 + UNLEAK(graph);
68 return verify_commit_graph(the_repository, graph);
69 }
70
@@ -89,10 +90,8 @@ static int graph_read(int argc, const char **argv)
90 graph_name = get_commit_graph_filename(opts.obj_dir);
91 graph = load_commit_graph_one(graph_name);
92
92 - if (!graph) {
93 - UNLEAK(graph_name);
93 + if (!graph)
94 die("graph file %s does not exist", graph_name);
95 - }
95
96 FREE_AND_NULL(graph_name);
97
@@ -115,7 +114,7 @@ static int graph_read(int argc, const char **argv)
114 printf(" large_edges");
115 printf("\n");
116
118 - free_commit_graph(graph);
117 + UNLEAK(graph);
118
119 return 0;
120 }
@@ -166,6 +165,8 @@ static int graph_write(int argc, const char **argv)
165 pack_indexes = &lines;
166 if (opts.stdin_commits)
167 commit_hex = &lines;
168 +
169 + UNLEAK(buf);
170 }
171
172 write_commit_graph(opts.obj_dir,
@@ -174,7 +175,7 @@ static int graph_write(int argc, const char **argv)
175 opts.append,
176 1);
177
177 - string_list_clear(&lines, 0);
178 + UNLEAK(lines);
179 return 0;
180 }
181