diff options
author | Andrzej Hunt <ajrhunt@google.com> | 2021-04-25 14:16:11 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-04-28 09:25:44 +0900 |
commit | b180c681bb911714e2c9735038effe0251d6586e (patch) | |
tree | b8f1194be8ce9de306d3d7e3e5ce5afb67235c9b | |
parent | ls-files: free max_prefix when done (diff) | |
download | tgif-b180c681bb911714e2c9735038effe0251d6586e.tar.xz |
bloom: clear each bloom_key after use
fill_bloom_key() allocates memory into bloom_key, we need to clean that
up once the key is no longer needed.
This leak was found while running t0002-t0099. Although this leak is
happening in code being called from a test-helper, the same code is also
used in various locations around git, and can therefore happen during
normal usage too. Gabor's analysis shows that peak-memory usage during
'git commit-graph write' is reduced on the order of 10% for a selection
of larger repos (along with an even larger reduction if we override
modified path bloom filter limits):
https://lore.kernel.org/git/20210411072651.GF2947267@szeder.dev/
LSAN output:
Direct leak of 308 byte(s) in 11 object(s) allocated from:
#0 0x49a5e2 in calloc ../projects/compiler-rt/lib/asan/asan_malloc_linux.cpp:154:3
#1 0x6f4032 in xcalloc wrapper.c:140:8
#2 0x4f2905 in fill_bloom_key bloom.c:137:28
#3 0x4f34c1 in get_or_compute_bloom_filter bloom.c:284:4
#4 0x4cb484 in get_bloom_filter_for_commit t/helper/test-bloom.c:43:11
#5 0x4cb072 in cmd__bloom t/helper/test-bloom.c:97:3
#6 0x4ca7ef in cmd_main t/helper/test-tool.c:121:11
#7 0x4caace in main common-main.c:52:11
#8 0x7f798af95349 in __libc_start_main (/lib64/libc.so.6+0x24349)
SUMMARY: AddressSanitizer: 308 byte(s) leaked in 11 allocation(s).
Signed-off-by: Andrzej Hunt <ajrhunt@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | bloom.c | 1 |
1 files changed, 1 insertions, 0 deletions
@@ -283,6 +283,7 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r, struct bloom_key key; fill_bloom_key(e->path, strlen(e->path), &key, settings); add_key_to_filter(&key, filter, settings); + clear_bloom_key(&key); } cleanup: |