Skip to content

Commit c4f75cc

Browse files
committed
midx-write: use cleanup when incremental midx fails
The incremental mode of writing a multi-pack-index has a few extra conditions that could lead to failure, but these are currently short-ciruiting with 'return -1' instead of setting the method's 'result' variable and going to the cleanup tag. Replace these returns with gotos to avoid memory issues when exiting early due to error conditions. Unfortunately, these error conditions are difficult to reproduce with test cases, which is perhaps one reason why the memory loss was not caught by existing test cases in memory tracking modes. Signed-off-by: Derrick Stolee <stolee@gmail.com>
1 parent a1dd3ed commit c4f75cc

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

midx-write.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,13 +1327,15 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
13271327
incr = mks_tempfile_m(midx_name.buf, 0444);
13281328
if (!incr) {
13291329
error(_("unable to create temporary MIDX layer"));
1330-
return -1;
1330+
result = -1;
1331+
goto cleanup;
13311332
}
13321333

13331334
if (adjust_shared_perm(r, get_tempfile_path(incr))) {
13341335
error(_("unable to adjust shared permissions for '%s'"),
13351336
get_tempfile_path(incr));
1336-
return -1;
1337+
result = -1;
1338+
goto cleanup;
13371339
}
13381340

13391341
f = hashfd(r->hash_algo, get_tempfile_fd(incr),
@@ -1433,18 +1435,22 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
14331435

14341436
if (!chainf) {
14351437
error_errno(_("unable to open multi-pack-index chain file"));
1436-
return -1;
1438+
result = -1;
1439+
goto cleanup;
14371440
}
14381441

1439-
if (link_midx_to_chain(ctx.base_midx) < 0)
1440-
return -1;
1442+
if (link_midx_to_chain(ctx.base_midx) < 0) {
1443+
result = -1;
1444+
goto cleanup;
1445+
}
14411446

14421447
get_split_midx_filename_ext(r->hash_algo, &final_midx_name,
14431448
object_dir, midx_hash, MIDX_EXT_MIDX);
14441449

14451450
if (rename_tempfile(&incr, final_midx_name.buf) < 0) {
14461451
error_errno(_("unable to rename new multi-pack-index layer"));
1447-
return -1;
1452+
result = -1;
1453+
goto cleanup;
14481454
}
14491455

14501456
strbuf_release(&final_midx_name);

0 commit comments

Comments
 (0)