Skip to content

Commit 2f07d22

Browse files
pks-tgitster
authored andcommitted
sequencer: release todo list on error paths
We're not releasing the `todo_list` in `sequencer_pick_revisions()` when hitting an error path. Restructure the function to have a common exit path such that we can easily clean up the list and thus plug this memory leak. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent de54b45 commit 2f07d22

File tree

2 files changed

+48
-19
lines changed

2 files changed

+48
-19
lines changed

sequencer.c

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5490,8 +5490,10 @@ int sequencer_pick_revisions(struct repository *r,
54905490
int i, res;
54915491

54925492
assert(opts->revs);
5493-
if (read_and_refresh_cache(r, opts))
5494-
return -1;
5493+
if (read_and_refresh_cache(r, opts)) {
5494+
res = -1;
5495+
goto out;
5496+
}
54955497

54965498
for (i = 0; i < opts->revs->pending.nr; i++) {
54975499
struct object_id oid;
@@ -5506,11 +5508,14 @@ int sequencer_pick_revisions(struct repository *r,
55065508
enum object_type type = oid_object_info(r,
55075509
&oid,
55085510
NULL);
5509-
return error(_("%s: can't cherry-pick a %s"),
5510-
name, type_name(type));
5511+
res = error(_("%s: can't cherry-pick a %s"),
5512+
name, type_name(type));
5513+
goto out;
55115514
}
5512-
} else
5513-
return error(_("%s: bad revision"), name);
5515+
} else {
5516+
res = error(_("%s: bad revision"), name);
5517+
goto out;
5518+
}
55145519
}
55155520

55165521
/*
@@ -5525,14 +5530,23 @@ int sequencer_pick_revisions(struct repository *r,
55255530
opts->revs->no_walk &&
55265531
!opts->revs->cmdline.rev->flags) {
55275532
struct commit *cmit;
5528-
if (prepare_revision_walk(opts->revs))
5529-
return error(_("revision walk setup failed"));
5533+
5534+
if (prepare_revision_walk(opts->revs)) {
5535+
res = error(_("revision walk setup failed"));
5536+
goto out;
5537+
}
5538+
55305539
cmit = get_revision(opts->revs);
5531-
if (!cmit)
5532-
return error(_("empty commit set passed"));
5540+
if (!cmit) {
5541+
res = error(_("empty commit set passed"));
5542+
goto out;
5543+
}
5544+
55335545
if (get_revision(opts->revs))
55345546
BUG("unexpected extra commit from walk");
5535-
return single_pick(r, cmit, opts);
5547+
5548+
res = single_pick(r, cmit, opts);
5549+
goto out;
55365550
}
55375551

55385552
/*
@@ -5542,16 +5556,30 @@ int sequencer_pick_revisions(struct repository *r,
55425556
*/
55435557

55445558
if (walk_revs_populate_todo(&todo_list, opts) ||
5545-
create_seq_dir(r) < 0)
5546-
return -1;
5547-
if (repo_get_oid(r, "HEAD", &oid) && (opts->action == REPLAY_REVERT))
5548-
return error(_("can't revert as initial commit"));
5549-
if (save_head(oid_to_hex(&oid)))
5550-
return -1;
5551-
if (save_opts(opts))
5552-
return -1;
5559+
create_seq_dir(r) < 0) {
5560+
res = -1;
5561+
goto out;
5562+
}
5563+
5564+
if (repo_get_oid(r, "HEAD", &oid) && (opts->action == REPLAY_REVERT)) {
5565+
res = error(_("can't revert as initial commit"));
5566+
goto out;
5567+
}
5568+
5569+
if (save_head(oid_to_hex(&oid))) {
5570+
res = -1;
5571+
goto out;
5572+
}
5573+
5574+
if (save_opts(opts)) {
5575+
res = -1;
5576+
goto out;
5577+
}
5578+
55535579
update_abort_safety_file();
55545580
res = pick_commits(r, &todo_list, opts);
5581+
5582+
out:
55555583
todo_list_release(&todo_list);
55565584
return res;
55575585
}

t/t3510-cherry-pick-sequence.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ test_description='Test cherry-pick continuation features
1212
1313
'
1414

15+
TEST_PASSES_SANITIZE_LEAK=true
1516
. ./test-lib.sh
1617

1718
# Repeat first match 10 times

0 commit comments

Comments
 (0)