]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diffcore-break: fix leaking filespecs when merging broken pairs
authorPatrick Steinhardt <ps@pks.im>
Thu, 26 Sep 2024 11:47:08 +0000 (13:47 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 27 Sep 2024 15:25:37 +0000 (08:25 -0700)
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>
diffcore-break.c
t/t4008-diff-break-rewrite.sh
t/t4022-diff-rewrite.sh
t/t4023-diff-rename-typechange.sh
t/t4031-diff-rewrite-binary.sh
t/t7524-commit-summary.sh

index 831b66b5c3e85c03f35aed8546ee1dfb62524afd..02735f80c6582e7f9305037ed1d77c8d7a243758 100644 (file)
@@ -266,8 +266,8 @@ static void merge_broken(struct diff_filepair *p,
         * in the resulting tree.
         */
        d->one->rename_used++;
-       diff_free_filespec_data(d->two);
-       diff_free_filespec_data(c->one);
+       free_filespec(d->two);
+       free_filespec(c->one);
        free(d);
        free(c);
 }
index 562aaf3a2a295e9bb800e1ff363a0209c8f893ba..b0ef0026e089ca0b410d0eab1fd45508ddfbe515 100755 (executable)
@@ -21,6 +21,8 @@ With -B, this should be detected as two complete rewrites.
 
 Further, with -B and -M together, these should turn into two renames.
 '
+
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash
 
index 6fed993ea0b34dddae94356354c889ada9f16497..77bc36d5d8fd983dcbe82577593e2fdaeb946925 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='rewrite diff'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-diff-data.sh
 
index 787605ce3fd076b101d1c825fca174020ae7ff46..e6f4fe441e1b0dc8516d930250cba1121fc46251 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='typechange rename detection'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-diff.sh
 
index c4394a27b56236aeda3c92df03aa19f9d8720190..1b8cd3e4c97dd8bd91be46f6141e4f87c5b01689 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='rewrite diff on binary file'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 # We must be large enough to meet the MINIMUM_BREAK_SIZE
index 47b2f1dc22a5cb8dafac61a9811cdc262793d06e..a8fceb6a47c3487099b8df3378e7fb3ac085c54c 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 test_description='git commit summary'
+
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'setup' '