]> git.ipfire.org Git - thirdparty/git.git/commitdiff
line-log: drop extra copy of range with bloom filters
authorJeff King <peff@peff.net>
Wed, 1 Jul 2026 06:42:03 +0000 (02:42 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Jul 2026 15:44:06 +0000 (08:44 -0700)
When line_log_process_ranges_arbitrary_commit() finds out from a Bloom
filter that a commit didn't touch the path in question, it can quickly
pass its range on to the parent commit.

It does so by making a copy of the range, and passing that copy to
add_line_range(). But add_line_range() already makes its own copy
(either directly, or by merging with an existing range for that parent).
So the copy we make is leaked.

We can plug the leak by just passing our range directly, without the
extra copy.

The bug goes back to f32dde8c12 (line-log: integrate with changed-path
Bloom filters, 2020-05-11). We didn't notice because the test suite
never explicitly combines these features! You can observe it by building
with SANITIZE=leak and running t4211 with some extra flags:

  GIT_TEST_COMMIT_GRAPH=1 \
  GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=1 \
  ./t4211-line-log.sh

It would probably be useful to have some more targeted test coverage of
these features together. But I don't think there's much point in just
blindly copying the existing tests and adding bloom-filter support. We
already do that via the linux-TEST-vars CI job. We just don't run the
leak-checking build with those flags (so if there were a correctness
problem, we'd have noticed, just not a leak).

So I think we'd benefit from somebody clueful thinking about the
interaction of these features and testing the corner cases. But for the
purposes of this leak fix, I think we can just rely on the recipe above
(and consider running an extra leak-test job with more TEST-vars set).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
line-log.c

index 858a899cd2a61db85532196ffcdf3b71336051eb..0a03f20118feb0f2478f5105070bdb73badfcaf0 100644 (file)
@@ -1153,8 +1153,7 @@ int line_log_process_ranges_arbitrary_commit(struct rev_info *rev, struct commit
 
        if (range) {
                if (commit->parents && !bloom_filter_check(rev, commit, range)) {
-                       struct line_log_data *prange = line_log_data_copy(range);
-                       add_line_range(rev, commit->parents->item, prange);
+                       add_line_range(rev, commit->parents->item, range);
                        clear_commit_line_range(rev, commit);
                } else if (commit->parents && commit->parents->next)
                        changed = process_ranges_merge_commit(rev, commit, range);