diff: free state populated via options

The `objfind` and `anchors` members of `struct diff_options` are populated via option parsing, but are never freed in `diff_free()`. Fix this to plug those memory leaks. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Aug 14, 2024 at 08:52 UTC 36f971f86182a25fa2fa4af680bf79f522a27f60
4 files changed +14
diff.c
+10
@@ -6717,6 +6717,16 @@ void diff_free(struct diff_options *options)
6717 if (options->no_free)
6718 return;
6719
6720 + if (options->objfind) {
6721 + oidset_clear(options->objfind);
6722 + FREE_AND_NULL(options->objfind);
6723 + }
6724 +
6725 + for (size_t i = 0; i < options->anchors_nr; i++)
6726 + free(options->anchors[i]);
6727 + FREE_AND_NULL(options->anchors);
6728 + options->anchors_nr = options->anchors_alloc = 0;
6729 +
6730 diff_free_file(options);
6731 diff_free_ignore_regex(options);
6732 clear_pathspec(&options->pathspec);
t/t4064-diff-oidfind.sh
+2
@@ -1,6 +1,8 @@
1 #!/bin/sh
2
3 test_description='test finding specific blobs in the revision walking'
4 +
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'setup ' '
t/t4065-diff-anchored.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='anchored diff algorithm'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success '--anchored' '
t/t4069-remerge-diff.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='remerge-diff handling'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 # This test is ort-specific