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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Aug 22, 2024 at 11:17 UTC fb24460e1d28d963eb0eac75d3342b492583d2c9
3 files changed +10 -1
t/helper/test-read-midx.c
+7 -1
@@ -86,6 +86,8 @@ static int read_midx_checksum(const char *object_dir)
86 if (!m)
87 return 1;
88 printf("%s\n", hash_to_hex(get_midx_checksum(m)));
89 +
90 + close_midx(m);
91 return 0;
92 }
93
@@ -102,10 +104,12 @@ static int read_midx_preferred_pack(const char *object_dir)
104
105 if (midx_preferred_pack(midx, &preferred_pack) < 0) {
106 warning(_("could not determine MIDX preferred pack"));
107 + close_midx(midx);
108 return 1;
109 }
110
111 printf("%s\n", midx->pack_names[preferred_pack]);
112 + close_midx(midx);
113 return 0;
114 }
115
@@ -122,8 +126,10 @@ static int read_midx_bitmapped_packs(const char *object_dir)
126 return 1;
127
128 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);
131 return 1;
132 + }
133
134 printf("%s\n", pack_basename(pack.p));
135 printf(" bitmap_pos: %"PRIuMAX"\n", (uintmax_t)pack.bitmap_pos);
t/t5319-multi-pack-index.sh
+2
@@ -1,6 +1,8 @@
1 #!/bin/sh
2
3 test_description='multi-pack-indexes'
4 +
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7 . "$TEST_DIRECTORY"/lib-chunk.sh
8 . "$TEST_DIRECTORY"/lib-midx.sh
t/t7704-repack-cruft.sh
+1
@@ -2,6 +2,7 @@
2
3 test_description='git repack works correctly'
4
5 +TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 objdir=.git/objects