@matheusbsbs / matheus-bagliano / commits / 65c425a2ec
Fork 0

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 <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Apr 3, 2020 at 21:11 UTC 65c425a2ec815989994716c81a2307ae5b5645bc
1 file changed +9 -4
sequencer.c
+9 -4
@@ -2485,6 +2485,7 @@ static int read_populate_opts(struct replay_opts *opts)
2485 {
2486 if (is_rebase_i(opts)) {
2487 struct strbuf buf = STRBUF_INIT;
2488 + int ret = 0;
2489
2490 if (read_oneliner(&buf, rebase_path_gpg_sign_opt(), 1)) {
2491 if (!starts_with(buf.buf, "-S"))
@@ -2525,7 +2526,7 @@ static int read_populate_opts(struct replay_opts *opts)
2526 opts->keep_redundant_commits = 1;
2527
2528 read_strategy_opts(opts, &buf);
2528 - strbuf_release(&buf);
2529 + strbuf_reset(&buf);
2530
2531 if (read_oneliner(&opts->current_fixups,
2532 rebase_path_current_fixups(), 1)) {
@@ -2538,12 +2539,16 @@ static int read_populate_opts(struct replay_opts *opts)
2539 }
2540
2541 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 + }
2546 opts->have_squash_onto = 1;
2547 }
2548
2546 - return 0;
2549 +done_rebase_i:
2550 + strbuf_release(&buf);
2551 + return ret;
2552 }
2553
2554 if (!file_exists(git_path_opts_file()))