Skip to content

Commit 65c425a

Browse files
Denton-Lgitster
authored andcommitted
sequencer: stop leaking buf
In read_populate_opts(), we call read_oneliner() _after_ calling strbuf_release(). This means that `buf` is leaked at the end of the function. Always clean up the strbuf by going to `done_rebase_i` whether or not we return an error. Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fd6852c commit 65c425a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

sequencer.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,6 +2485,7 @@ static int read_populate_opts(struct replay_opts *opts)
24852485
{
24862486
if (is_rebase_i(opts)) {
24872487
struct strbuf buf = STRBUF_INIT;
2488+
int ret = 0;
24882489

24892490
if (read_oneliner(&buf, rebase_path_gpg_sign_opt(), 1)) {
24902491
if (!starts_with(buf.buf, "-S"))
@@ -2525,7 +2526,7 @@ static int read_populate_opts(struct replay_opts *opts)
25252526
opts->keep_redundant_commits = 1;
25262527

25272528
read_strategy_opts(opts, &buf);
2528-
strbuf_release(&buf);
2529+
strbuf_reset(&buf);
25292530

25302531
if (read_oneliner(&opts->current_fixups,
25312532
rebase_path_current_fixups(), 1)) {
@@ -2538,12 +2539,16 @@ static int read_populate_opts(struct replay_opts *opts)
25382539
}
25392540

25402541
if (read_oneliner(&buf, rebase_path_squash_onto(), 0)) {
2541-
if (get_oid_hex(buf.buf, &opts->squash_onto) < 0)
2542-
return error(_("unusable squash-onto"));
2542+
if (get_oid_hex(buf.buf, &opts->squash_onto) < 0) {
2543+
ret = error(_("unusable squash-onto"));
2544+
goto done_rebase_i;
2545+
}
25432546
opts->have_squash_onto = 1;
25442547
}
25452548

2546-
return 0;
2549+
done_rebase_i:
2550+
strbuf_release(&buf);
2551+
return ret;
25472552
}
25482553

25492554
if (!file_exists(git_path_opts_file()))

0 commit comments

Comments
 (0)