mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01: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:
committed by
Junio C Hamano
parent
ae3196a5ea
commit
71c7916053
4
apply.c
4
apply.c
@@ -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;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
test_description='git checkout --patch'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./lib-patch-mode.sh
|
||||
|
||||
test_expect_success 'setup' '
|
||||
|
||||
@@ -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' '
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
test_description='git apply trying to add an ending line.
|
||||
|
||||
'
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
# setup
|
||||
|
||||
@@ -7,6 +7,7 @@ test_description='git apply with rejects
|
||||
|
||||
'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success setup '
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
test_description='test am --quoted-cr=<action>'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
DATA="$TEST_DIRECTORY/t4258"
|
||||
|
||||
Reference in New Issue
Block a user