unpack-file: fix ancient leak in create_temp_file()
Fix a leak that's been with us since 3407bb4940c (Add "unpack-file" helper that unpacks a sha1 blob into a tmpfile., 2005-04-18). See 00c8fd493af (cat-file: use streaming API to print blobs, 2012-03-07) for prior art which shows the same API pattern, i.e. free()-ing the result of read_object_file() after it's used. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>
Ævar Arnfjörð Bjarmason committed
Nov 8, 2022 at 19:17 UTC
e84a26e32faba0c2ae7a19fa9bf805645f620e82
6 files changed
+8
builtin/unpack-file.c
+1
@@ -19,6 +19,7 @@ static char *create_temp_file(struct object_id *oid)
19
if (write_in_full(fd, buf, size) < 0)
20
die_errno("unable to write temp-file");
21
close(fd);
22
+ free(buf);
23
return path;
24
}
25
t/t6060-merge-index.sh
+2
@@ -1,6 +1,8 @@
1
#!/bin/sh
2
3
test_description='basic git merge-index / git-merge-one-file tests'
4
+
5
+TEST_PASSES_SANITIZE_LEAK=true
6
. ./test-lib.sh
7
8
test_expect_success 'setup diverging branches' '
t/t6401-merge-criss-cross.sh
+2
@@ -8,6 +8,8 @@
8
9
10
test_description='Test criss-cross merge'
11
+
12
+TEST_PASSES_SANITIZE_LEAK=true
13
. ./test-lib.sh
14
15
test_expect_success 'prepare repository' '
t/t6406-merge-attr.sh
+1
@@ -8,6 +8,7 @@ test_description='per path merge controlled by merge attribute'
8
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
11
+TEST_PASSES_SANITIZE_LEAK=true
12
. ./test-lib.sh
13
14
test_expect_success setup '
t/t6407-merge-binary.sh
+1
@@ -5,6 +5,7 @@ test_description='ask merge-recursive to merge binary files'
5
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8
+TEST_PASSES_SANITIZE_LEAK=true
9
. ./test-lib.sh
10
11
test_expect_success setup '
t/t7605-merge-resolve.sh
+1
@@ -4,6 +4,7 @@ test_description='git merge
4
5
Testing the resolve strategy.'
6
7
+TEST_PASSES_SANITIZE_LEAK=true
8
. ./test-lib.sh
9
10
test_expect_success 'setup' '