From 9c8a9ec787149dc4f4b278d9bd8ad94c96691a5f Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Tue, 25 Jun 2024 13:40:15 -0400 Subject: bloom: introduce `deinit_bloom_filters()` After we are done using Bloom filters, we do not currently clean up any memory allocated by the commit slab used to store those filters in the first place. Besides the bloom_filter structures themselves, there is mostly nothing to free() in the first place, since in the read-only path all Bloom filter's `data` members point to a memory mapped region in the commit-graph file itself. But when generating Bloom filters from scratch (or initializing truncated filters) we allocate additional memory to store the filter's data. Keep track of when we need to free() this additional chunk of memory by using an extra pointer `to_free`. Most of the time this will be NULL (indicating that we are representing an existing Bloom filter stored in a memory mapped region). When it is non-NULL, free it before discarding the Bloom filters slab. Suggested-by: Jonathan Tan Signed-off-by: Taylor Blau Signed-off-by: Junio C Hamano Signed-off-by: Taylor Blau Signed-off-by: Junio C Hamano --- commit-graph.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'commit-graph.c') diff --git a/commit-graph.c b/commit-graph.c index e401e31a78..0de0f38b53 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -828,6 +828,7 @@ struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r) void close_commit_graph(struct raw_object_store *o) { clear_commit_graph_data_slab(&commit_graph_data_slab); + deinit_bloom_filters(); free_commit_graph(o->commit_graph); o->commit_graph = NULL; } @@ -2646,6 +2647,9 @@ int write_commit_graph(struct object_directory *odb, res = write_commit_graph_file(ctx); + if (ctx->changed_paths) + deinit_bloom_filters(); + if (ctx->split) mark_commit_graphs(ctx); -- cgit 1.2.3-korg