1
0
mirror of https://github.com/git/git synced 2024-06-30 22:54:27 +00:00

apply: plug a leak in apply_data

We have an execution path in apply_data that leaks the local struct
image.  Plug it.

This leak can be triggered with:

    $ echo foo >file
    $ git add file && git commit -m file
    $ echo bar >file
    $ git diff file >diff
    $ sed s/foo/frotz/ <diff >baddiff
    $ git apply --cached <baddiff

Fixing this leak allows us to mark as leak-free the following tests:

    + t2016-checkout-patch.sh
    + t4103-apply-binary.sh
    + t4104-apply-boundary.sh
    + t4113-apply-ending.sh
    + t4117-apply-reject.sh
    + t4123-apply-shrink.sh
    + t4252-am-options.sh
    + t4258-am-quoted-cr.sh

Mark them with "TEST_PASSES_SANITIZE_LEAK=true" to notice and fix
promply any new leak that may be introduced and triggered by them in the
future.

Signed-off-by: Rubén Justo <rjusto@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Rubén Justo 2024-04-23 00:54:05 +02:00 committed by Junio C Hamano
parent ae3196a5ea
commit 71c7916053
9 changed files with 12 additions and 1 deletions

View File

@ -3712,8 +3712,10 @@ static int apply_data(struct apply_state *state, struct patch *patch,
fprintf(stderr, _("Falling back to direct application...\n"));
/* Note: with --reject, apply_fragments() returns 0 */
if (patch->direct_to_threeway || apply_fragments(state, &image, patch) < 0)
if (patch->direct_to_threeway || apply_fragments(state, &image, patch) < 0) {
clear_image(&image);
return -1;
}
}
patch->result = image.buf;
patch->resultsize = image.len;

View File

@ -2,6 +2,7 @@
test_description='git checkout --patch'
TEST_PASSES_SANITIZE_LEAK=true
. ./lib-patch-mode.sh
test_expect_success 'setup' '

View File

@ -9,6 +9,7 @@ test_description='git apply handling binary patches
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'setup' '

View File

@ -5,6 +5,7 @@
test_description='git apply boundary tests'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
L="c d e f g h i j k l m n o p q r s t u v w x"

View File

@ -6,6 +6,7 @@
test_description='git apply trying to add an ending line.
'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
# setup

View File

@ -7,6 +7,7 @@ test_description='git apply with rejects
'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success setup '

View File

@ -2,6 +2,7 @@
test_description='apply a patch that is larger than the preimage'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
cat >F <<\EOF

View File

@ -1,6 +1,8 @@
#!/bin/sh
test_description='git am with options and not losing them'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
tm="$TEST_DIRECTORY/t4252"

View File

@ -2,6 +2,7 @@
test_description='test am --quoted-cr=<action>'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
DATA="$TEST_DIRECTORY/t4258"