Skip to content

Commit fb24460

Browse files
pks-tgitster
authored andcommitted
t/helper: fix leaking multi-pack-indices in "read-midx"
Several of the subcommands of `test-helper read-midx` do not close the MIDX that they have opened, leading to memory leaks. Fix those. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bda97cb commit fb24460

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

t/helper/test-read-midx.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ static int read_midx_checksum(const char *object_dir)
8686
if (!m)
8787
return 1;
8888
printf("%s\n", hash_to_hex(get_midx_checksum(m)));
89+
90+
close_midx(m);
8991
return 0;
9092
}
9193

@@ -102,10 +104,12 @@ static int read_midx_preferred_pack(const char *object_dir)
102104

103105
if (midx_preferred_pack(midx, &preferred_pack) < 0) {
104106
warning(_("could not determine MIDX preferred pack"));
107+
close_midx(midx);
105108
return 1;
106109
}
107110

108111
printf("%s\n", midx->pack_names[preferred_pack]);
112+
close_midx(midx);
109113
return 0;
110114
}
111115

@@ -122,8 +126,10 @@ static int read_midx_bitmapped_packs(const char *object_dir)
122126
return 1;
123127

124128
for (i = 0; i < midx->num_packs + midx->num_packs_in_base; i++) {
125-
if (nth_bitmapped_pack(the_repository, midx, &pack, i) < 0)
129+
if (nth_bitmapped_pack(the_repository, midx, &pack, i) < 0) {
130+
close_midx(midx);
126131
return 1;
132+
}
127133

128134
printf("%s\n", pack_basename(pack.p));
129135
printf(" bitmap_pos: %"PRIuMAX"\n", (uintmax_t)pack.bitmap_pos);

t/t5319-multi-pack-index.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='multi-pack-indexes'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57
. "$TEST_DIRECTORY"/lib-chunk.sh
68
. "$TEST_DIRECTORY"/lib-midx.sh

t/t7704-repack-cruft.sh

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

33
test_description='git repack works correctly'
44

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

78
objdir=.git/objects

0 commit comments

Comments
 (0)