commit-graph: free all elements of graph chain
When running "commit-graph verify", we call free_commit_graph(). That's sufficient for the case of a single graph file, but if we loaded a chain of split graph files, they form a linked list via the base_graph pointers. We need to free all of them, or we leak all but the first struct. We can make this work by teaching free_commit_graph() to walk the base_graph pointers and free each element. This in turn lets us simplify close_commit_graph(), which does the same thing by recursion (we cannot just use close_commit_graph() in "commit-graph verify", as the function takes a pointer to an object store, and the verify command creates a single one-off graph struct). While indenting the code in free_commit_graph() for the loop, I noticed that setting g->data to NULL is rather pointless, as we free the struct a few lines later. So I cleaned that up while we're here. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
ac6d45d11f
commit
09a75abba4
@ -723,19 +723,10 @@ struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void close_commit_graph_one(struct commit_graph *g)
|
|
||||||
{
|
|
||||||
if (!g)
|
|
||||||
return;
|
|
||||||
|
|
||||||
close_commit_graph_one(g->base_graph);
|
|
||||||
free_commit_graph(g);
|
|
||||||
}
|
|
||||||
|
|
||||||
void close_commit_graph(struct raw_object_store *o)
|
void close_commit_graph(struct raw_object_store *o)
|
||||||
{
|
{
|
||||||
clear_commit_graph_data_slab(&commit_graph_data_slab);
|
clear_commit_graph_data_slab(&commit_graph_data_slab);
|
||||||
close_commit_graph_one(o->commit_graph);
|
free_commit_graph(o->commit_graph);
|
||||||
o->commit_graph = NULL;
|
o->commit_graph = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2753,15 +2744,17 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
|
|||||||
|
|
||||||
void free_commit_graph(struct commit_graph *g)
|
void free_commit_graph(struct commit_graph *g)
|
||||||
{
|
{
|
||||||
if (!g)
|
while (g) {
|
||||||
return;
|
struct commit_graph *next = g->base_graph;
|
||||||
if (g->data) {
|
|
||||||
munmap((void *)g->data, g->data_len);
|
if (g->data)
|
||||||
g->data = NULL;
|
munmap((void *)g->data, g->data_len);
|
||||||
|
free(g->filename);
|
||||||
|
free(g->bloom_filter_settings);
|
||||||
|
free(g);
|
||||||
|
|
||||||
|
g = next;
|
||||||
}
|
}
|
||||||
free(g->filename);
|
|
||||||
free(g->bloom_filter_settings);
|
|
||||||
free(g);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void disable_commit_graph(struct repository *r)
|
void disable_commit_graph(struct repository *r)
|
||||||
|
Reference in New Issue
Block a user