mirror of
https://github.com/git/git.git
synced 2024-11-23 18:05:29 +08:00
27472b5195
Fix a memory leak where "cat-file" will leak the "path" member. Seee5fba602e5
(textconv: support for cat_file, 2010-06-15) for the code that introduced the offending get_oid_with_context() call (called get_sha1_with_context() at the time). As a result we can mark several tests as passing with SANITIZE=leak using "TEST_PASSES_SANITIZE_LEAK=true". As noted indc944b65f1
(get_sha1_with_context: dynamically allocate oc->path, 2017-05-19) callers must free the "path" member. That same commit added the relevant free() to this function, but we weren't catching cases where we'd return early. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
58 lines
1.3 KiB
Bash
Executable File
58 lines
1.3 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='git apply of i-t-a file'
|
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success setup '
|
|
test_write_lines 1 2 3 4 5 >blueprint &&
|
|
|
|
cat blueprint >test-file &&
|
|
git add -N test-file &&
|
|
git diff >creation-patch &&
|
|
grep "new file mode 100644" creation-patch &&
|
|
|
|
rm -f test-file &&
|
|
git diff >deletion-patch &&
|
|
grep "deleted file mode 100644" deletion-patch
|
|
'
|
|
|
|
test_expect_success 'apply creation patch to ita path (--cached)' '
|
|
git rm -f test-file &&
|
|
cat blueprint >test-file &&
|
|
git add -N test-file &&
|
|
|
|
git apply --cached creation-patch &&
|
|
git cat-file blob :test-file >actual &&
|
|
test_cmp blueprint actual
|
|
'
|
|
|
|
test_expect_success 'apply creation patch to ita path (--index)' '
|
|
git rm -f test-file &&
|
|
cat blueprint >test-file &&
|
|
git add -N test-file &&
|
|
rm -f test-file &&
|
|
|
|
test_must_fail git apply --index creation-patch
|
|
'
|
|
|
|
test_expect_success 'apply deletion patch to ita path (--cached)' '
|
|
git rm -f test-file &&
|
|
cat blueprint >test-file &&
|
|
git add -N test-file &&
|
|
|
|
git apply --cached deletion-patch &&
|
|
test_must_fail git ls-files --stage --error-unmatch test-file
|
|
'
|
|
|
|
test_expect_success 'apply deletion patch to ita path (--index)' '
|
|
cat blueprint >test-file &&
|
|
git add -N test-file &&
|
|
|
|
test_must_fail git apply --index deletion-patch &&
|
|
git ls-files --stage --error-unmatch test-file
|
|
'
|
|
|
|
test_done
|