]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff: free state populated via options
authorPatrick Steinhardt <ps@pks.im>
Wed, 14 Aug 2024 06:52:55 +0000 (08:52 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Aug 2024 17:08:01 +0000 (10:08 -0700)
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>
diff.c
t/t4064-diff-oidfind.sh
t/t4065-diff-anchored.sh
t/t4069-remerge-diff.sh

diff --git a/diff.c b/diff.c
index 9251c47b728799899adb4be9b462179b1807d198..4035a9374d52e17d1332053d6d7396851a042876 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -6717,6 +6717,16 @@ void diff_free(struct diff_options *options)
        if (options->no_free)
                return;
 
+       if (options->objfind) {
+               oidset_clear(options->objfind);
+               FREE_AND_NULL(options->objfind);
+       }
+
+       for (size_t i = 0; i < options->anchors_nr; i++)
+               free(options->anchors[i]);
+       FREE_AND_NULL(options->anchors);
+       options->anchors_nr = options->anchors_alloc = 0;
+
        diff_free_file(options);
        diff_free_ignore_regex(options);
        clear_pathspec(&options->pathspec);
index 6d8c8986fc71e4570c4c728e3ae1bc9e9d5faac6..846f285f772e53abd13adce7add205d0a59c8d1f 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 test_description='test finding specific blobs in the revision walking'
+
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup ' '
index b3f510f040ec3b955ff53c3de81ffc5a60ad3862..647537c12ea99db2594b1e29aa2c68027055d611 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='anchored diff algorithm'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success '--anchored' '
index 07323ebafe0d0cb49f08c4396116fa1f45687cd8..888714bbd36177cbd15173f9afd308f5da433dc0 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='remerge-diff handling'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 # This test is ort-specific