Skip to content

Commit 6b7d812

Browse files
ttaylorrgitster
authored andcommitted
t/helper/test-read-midx.c: plug memory leak when selecting layer
Though our 'read-midx' test tool is capable of printing information about a single MIDX layer identified by its checksum, no caller in our test suite exercises this path. Unfortunately, there is a memory leak lurking in this (currently) unused path that would otherwise be exposed by the following commit. This occurs when providing a MIDX layer checksum other than the tip. As we walk over the MIDX chain trying to find the matching layer, we drop our reference to the top-most MIDX layer. Thus, our call to 'close_midx()' later on leaks memory between the top-most MIDX layer and the MIDX layer immediately following the specified one. Plug this leak by holding a reference to the tip of the MIDX chain, and ensure that we call `close_midx()` before terminating the test tool. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 477f9c1 commit 6b7d812

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

t/helper/test-read-midx.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,22 @@ static int read_midx_file(const char *object_dir, const char *checksum,
2626
int show_objects)
2727
{
2828
uint32_t i;
29-
struct multi_pack_index *m;
29+
struct multi_pack_index *m, *tip;
30+
int ret = 0;
3031

31-
m = setup_midx(object_dir);
32+
m = tip = setup_midx(object_dir);
3233

3334
if (!m)
3435
return 1;
3536

3637
if (checksum) {
3738
while (m && strcmp(get_midx_checksum(m), checksum))
3839
m = m->base_midx;
39-
if (!m)
40-
return 1;
40+
if (!m) {
41+
ret = error(_("could not find MIDX with checksum %s"),
42+
checksum);
43+
goto out;
44+
}
4145
}
4246

4347
printf("header: %08x %d %d %d %d\n",
@@ -82,9 +86,10 @@ static int read_midx_file(const char *object_dir, const char *checksum,
8286
}
8387
}
8488

85-
close_midx(m);
89+
out:
90+
close_midx(tip);
8691

87-
return 0;
92+
return ret;
8893
}
8994

9095
static int read_midx_checksum(const char *object_dir)

0 commit comments

Comments
 (0)