diffcore-break: fix leaking filespecs when merging broken pairs

When merging file pairs after they have been broken up we queue a new file pair and discard the broken-up ones. The newly-queued file pair reuses one filespec of the broken up pairs each, where the respective other filespec gets discarded. But we only end up freeing the filespec's data, not the filespec itself, and thus leak memory. Fix these leaks by using `free_filespec()` instead. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Sep 26, 2024 at 13:47 UTC 12dfc2475ce4808df696fb67fc71a66793f78f06
6 files changed +9 -2
diffcore-break.c
+2 -2
@@ -266,8 +266,8 @@ static void merge_broken(struct diff_filepair *p,
266 * in the resulting tree.
267 */
268 d->one->rename_used++;
269 - diff_free_filespec_data(d->two);
270 - diff_free_filespec_data(c->one);
269 + free_filespec(d->two);
270 + free_filespec(c->one);
271 free(d);
272 free(c);
273 }
t/t4008-diff-break-rewrite.sh
+2
@@ -21,6 +21,8 @@ With -B, this should be detected as two complete rewrites.
21
22 Further, with -B and -M together, these should turn into two renames.
23 '
24 +
25 +TEST_PASSES_SANITIZE_LEAK=true
26 . ./test-lib.sh
27 . "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash
28
t/t4022-diff-rewrite.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='rewrite diff'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7 . "$TEST_DIRECTORY"/lib-diff-data.sh
8
t/t4023-diff-rename-typechange.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='typechange rename detection'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7 . "$TEST_DIRECTORY"/lib-diff.sh
8
t/t4031-diff-rewrite-binary.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='rewrite diff on binary file'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 # We must be large enough to meet the MINIMUM_BREAK_SIZE
t/t7524-commit-summary.sh
+2
@@ -1,6 +1,8 @@
1 #!/bin/sh
2
3 test_description='git commit summary'
4 +
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_expect_success 'setup' '