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 <jonathantanmy@google.com> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
5421e7c3a1
commit
9c8a9ec787
3
bloom.h
3
bloom.h
@ -56,6 +56,8 @@ struct bloom_filter {
|
||||
unsigned char *data;
|
||||
size_t len;
|
||||
int version;
|
||||
|
||||
void *to_free;
|
||||
};
|
||||
|
||||
/*
|
||||
@ -96,6 +98,7 @@ void add_key_to_filter(const struct bloom_key *key,
|
||||
const struct bloom_filter_settings *settings);
|
||||
|
||||
void init_bloom_filters(void);
|
||||
void deinit_bloom_filters(void);
|
||||
|
||||
enum bloom_filter_computed {
|
||||
BLOOM_NOT_COMPUTED = (1 << 0),
|
||||
|
Reference in New Issue
Block a user