Skip to content

Commit f40a693

Browse files
avargitster
authored andcommitted
test-tool delta: fix a memory leak
Fix a memory leak introduced in a310d43 ([PATCH] Deltification library work by Nicolas Pitre., 2005-05-19), as a result we can mark another test as passing with SANITIZE=leak using "TEST_PASSES_SANITIZE_LEAK=true". Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 34e6912 commit f40a693

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

t/helper/test-delta.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ int cmd__delta(int argc, const char **argv)
2020
{
2121
int fd;
2222
struct stat st;
23-
void *from_buf, *data_buf, *out_buf;
23+
void *from_buf = NULL, *data_buf = NULL, *out_buf = NULL;
2424
unsigned long from_size, data_size, out_size;
25+
int ret = 1;
2526

2627
if (argc != 5 || (strcmp(argv[1], "-d") && strcmp(argv[1], "-p"))) {
2728
fprintf(stderr, "usage: %s\n", usage_str);
@@ -38,21 +39,21 @@ int cmd__delta(int argc, const char **argv)
3839
if (read_in_full(fd, from_buf, from_size) < 0) {
3940
perror(argv[2]);
4041
close(fd);
41-
return 1;
42+
goto cleanup;
4243
}
4344
close(fd);
4445

4546
fd = open(argv[3], O_RDONLY);
4647
if (fd < 0 || fstat(fd, &st)) {
4748
perror(argv[3]);
48-
return 1;
49+
goto cleanup;
4950
}
5051
data_size = st.st_size;
5152
data_buf = xmalloc(data_size);
5253
if (read_in_full(fd, data_buf, data_size) < 0) {
5354
perror(argv[3]);
5455
close(fd);
55-
return 1;
56+
goto cleanup;
5657
}
5758
close(fd);
5859

@@ -66,14 +67,20 @@ int cmd__delta(int argc, const char **argv)
6667
&out_size);
6768
if (!out_buf) {
6869
fprintf(stderr, "delta operation failed (returned NULL)\n");
69-
return 1;
70+
goto cleanup;
7071
}
7172

7273
fd = open (argv[4], O_WRONLY|O_CREAT|O_TRUNC, 0666);
7374
if (fd < 0 || write_in_full(fd, out_buf, out_size) < 0) {
7475
perror(argv[4]);
75-
return 1;
76+
goto cleanup;
7677
}
7778

78-
return 0;
79+
ret = 0;
80+
cleanup:
81+
free(from_buf);
82+
free(data_buf);
83+
free(out_buf);
84+
85+
return ret;
7986
}

t/t5303-pack-corruption-resilience.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#
55

66
test_description='resilience to pack corruptions with redundant objects'
7+
8+
TEST_PASSES_SANITIZE_LEAK=true
79
. ./test-lib.sh
810

911
# Note: the test objects are created with knowledge of their pack encoding

0 commit comments

Comments
 (0)