builtin/rebase.c: fix "options.onto_name" leak

Similar to the existing "squash_onto_name" added in [1] we need to free() the xstrdup()'d "options.onto.name" added for "--keep-base" in [2].. 1. 9dba809a69a (builtin rebase: support --root, 2018-09-04) 2. 414d924beb4 (rebase: teach rebase --keep-base, 2019-08-27) Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 6, 2023 at 20:08 UTC 94ad545d47afe2b73dad871635b92956644815f5
2 files changed +4 -1
builtin/rebase.c
+3 -1
@@ -1039,6 +1039,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1039 struct string_list strategy_options = STRING_LIST_INIT_NODUP;
1040 struct object_id squash_onto;
1041 char *squash_onto_name = NULL;
1042 + char *keep_base_onto_name = NULL;
1043 int reschedule_failed_exec = -1;
1044 int allow_preemptive_ff = 1;
1045 int preserve_merges_selected = 0;
@@ -1675,7 +1676,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1676 strbuf_addstr(&buf, options.upstream_name);
1677 strbuf_addstr(&buf, "...");
1678 strbuf_addstr(&buf, branch_name);
1678 - options.onto_name = xstrdup(buf.buf);
1679 + options.onto_name = keep_base_onto_name = xstrdup(buf.buf);
1680 } else if (!options.onto_name)
1681 options.onto_name = options.upstream_name;
1682 if (strstr(options.onto_name, "...")) {
@@ -1851,6 +1852,7 @@ cleanup:
1852 free(options.strategy);
1853 strbuf_release(&options.git_format_patch_opt);
1854 free(squash_onto_name);
1855 + free(keep_base_onto_name);
1856 string_list_clear(&strategy_options, 0);
1857 return !!ret;
1858 }
t/t3416-rebase-onto-threedots.sh
+1
@@ -5,6 +5,7 @@ test_description='git rebase --onto A...B'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 +TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10 . "$TEST_DIRECTORY/lib-rebase.sh"
11