Skip to content

Commit 71c7916

Browse files
rjustogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ae3196a commit 71c7916

9 files changed

+12
-1
lines changed

apply.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3712,8 +3712,10 @@ static int apply_data(struct apply_state *state, struct patch *patch,
37123712
fprintf(stderr, _("Falling back to direct application...\n"));
37133713

37143714
/* Note: with --reject, apply_fragments() returns 0 */
3715-
if (patch->direct_to_threeway || apply_fragments(state, &image, patch) < 0)
3715+
if (patch->direct_to_threeway || apply_fragments(state, &image, patch) < 0) {
3716+
clear_image(&image);
37163717
return -1;
3718+
}
37173719
}
37183720
patch->result = image.buf;
37193721
patch->resultsize = image.len;

t/t2016-checkout-patch.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='git checkout --patch'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./lib-patch-mode.sh
67

78
test_expect_success 'setup' '

t/t4103-apply-binary.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test_description='git apply handling binary patches
99
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
1010
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1111

12+
TEST_PASSES_SANITIZE_LEAK=true
1213
. ./test-lib.sh
1314

1415
test_expect_success 'setup' '

t/t4104-apply-boundary.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
test_description='git apply boundary tests'
77

8+
TEST_PASSES_SANITIZE_LEAK=true
89
. ./test-lib.sh
910

1011
L="c d e f g h i j k l m n o p q r s t u v w x"

t/t4113-apply-ending.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
test_description='git apply trying to add an ending line.
77
88
'
9+
TEST_PASSES_SANITIZE_LEAK=true
910
. ./test-lib.sh
1011

1112
# setup

t/t4117-apply-reject.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ test_description='git apply with rejects
77
88
'
99

10+
TEST_PASSES_SANITIZE_LEAK=true
1011
. ./test-lib.sh
1112

1213
test_expect_success setup '

t/t4123-apply-shrink.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='apply a patch that is larger than the preimage'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
cat >F <<\EOF

t/t4252-am-options.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

33
test_description='git am with options and not losing them'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57

68
tm="$TEST_DIRECTORY/t4252"

t/t4258-am-quoted-cr.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='test am --quoted-cr=<action>'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
DATA="$TEST_DIRECTORY/t4258"

0 commit comments

Comments
 (0)